1

I have an STM32F429ZI Nucleo board (for SPI master and UART to check everything's working alright) and an EVB-LAN9252-SPI board(for SPI slave).

I have to check if the SPI is correctly working, but it seems that I can't debug or check on the slave's side.

Shown below is the test code that I worked on the STM32F429ZI Nucleo board to check if the SPI is working correctly. SPI1 and SPI4 is configured in one board.

  while (k < 32)
  {
    HAL_UART_Transmit(&huart4, &SPI1_Buffer_Tx[k], 1, 100);
    k++;
  }
  k = 0;

  while (k < 32)
  {
    HAL_GPIO_WritePin(GPIOE, GPIO_PIN_9, GPIO_PIN_RESET); // this GPIO is connected to hardware NSS
    HAL_SPI_Transmit(&hspi1, &SPI1_Buffer_Tx[k], 1, 100);
    HAL_SPI_Receive(&hspi4, &SPI4_Buffer_Rx[k], 1, 100);
    HAL_GPIO_WritePin(GPIOE, GPIO_PIN_9, GPIO_PIN_SET);
    k++;
  }
  k = 0;

  while (k < 32)
  {
    HAL_UART_Transmit(&huart4, &SPI1_Buffer_Tx[k], 1, 100);
    k++;
  }
  k = 0;

  while (k < 32)
  {
    HAL_UART_Transmit(&huart4, &SPI4_Buffer_Rx[k], 1, 100);
    k++;
  }

In this case the UART shows me such answer

abcdefghijklmnopqrstuvwxyzABCDEF //what was originally in the transmit buffer
 bcdefghijklmnopqrstuvwxyzABCDEF //what was received in the receive buffer

Maybe this was possible because I could read on the slave's side, with such code

HAL_SPI_Receive(&hspi4, &SPI4_Buffer_Rx[k], 1, 100);

Now back to the original project.

At first I assumed that the data transmitted from the master should circulate in the slave somehow and transmit back to the master, so that if I read from the master I should get the original data, but in backwards.

so this was the code.

  while (k < 32)
  {
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
    HAL_SPI_Transmit(&hspi1, &SPI1_Buffer_Tx[k], 1, 100);
    HAL_SPI_Receive(&hspi1, &SPI1_Buffer_Rx[k], 1, 100);
    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
    k++;
  }

and what I received from the master is 32 0xFFs. I'm not sure where I'm wrong about.

  1. Does the data actually circulate in the slave's side and is it just me doing something wrong?
  2. The data seems to be correctly transmitted, but the slave hasn't been ordered to transmit anything back to the master. That's why I can't receive meaningful data from the master.

2-1. If so, how do I know that the slave has received the data correctly?

2-2. How do I order the slave to transmit back to the master some meaningful data? I can only debug my code on the master's board.

Junseok Oh
  • 11
  • 3
  • Hi, you have posted this also on the ST stm32 forum and already received answers there. – ddbug Sep 02 '22 at 09:44
  • maybe you could connect MISO with MOSI? In the same SPI you should recieve what you transmit – WITC Sep 02 '22 at 11:25
  • 1
    Nucleo boards have an ST-Link debug interface; that is a far more effective debug, test and development interface than the UART. – Clifford Sep 02 '22 at 13:15
  • 2
    The received data is a matter of how the slave works. Many devices operate in a simplex mode, outputting dummy 0xFF data whilst receiving. What you should do is send valid sequences to the slave that it will understand and process and which will precipitate some sort of response, then validate that response. There is no generic SPI behaviour you can check, you have to check the behaviour of the slave device as defined in its datasheet. – Clifford Sep 02 '22 at 13:21
  • ... for example, a simple test would be to periodically read the FR_CNT free-running counter. It increments at 25MHz, so if you read it repeatedly, the value should change monotonically, and if you time the readings you could verify the frequency. That would indicate that the LAN9252 is running as well as verifying SPI comms. – Clifford Sep 02 '22 at 13:41
  • You may test the host itself in a loopback (internal or external) mode. Otherwise it fully depends on the what is the peripheral doing and its protocol. – 0andriy Sep 05 '22 at 09:32
  • Please take the [tour] to learn how this site works. This is not a forum. Please do not put "completed" or "solved" into your title, and do not add solutions to the question. Instead write an answer and accept it. – the busybee Sep 28 '22 at 09:56
  • oops! fixed it. thanks for letting me know! – Junseok Oh Sep 30 '22 at 06:03

1 Answers1

0

Thanks for your kind comments!

It took a whole month for me to get this work done, and I'm sure there'll be newbies like me in the future, so..

As in the LAN9252 Datasheet page 302/329 and 303/329, you can send "0x0050" to receive "0x92520001", and "0x0064" to receive "0x87654321".

the way you send the data is kinda delicate, and that was the part I kept failing. I was (and am) not fully understanding the principles of SPI communication and you're gonna need an oscilloscope with multiple probes(It took me only 2 days after using the oscilloscope, because before then I couldn't check what I was doing).

Junseok Oh
  • 11
  • 3