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 0xFF
s.
I'm not sure where I'm wrong about.
- Does the data actually circulate in the slave's side and is it just me doing something wrong?
- 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.