I'm trying to do simple SPI communication on STM32 Discovery, HAL lib is used. I'm trying to send some data via SPI1 and to receive same data on SPI3 (SPI1 = Full Duplex Master, SPI3 = Full Duplex Slave). For transmit polling method is used and for receive DMA circular. Communication is on 1 device (just one Discovery is used). Code stuck here:
while(HAL_SPI_GetState(&hspi3) != HAL_SPI_STATE_READY){}
Can someone explain me why code stuck there?
uint8_t rxSpi[10] = {0};
uint8_t txSpi[10] = "123456788";
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DMA_Init();
MX_SPI1_Init();
MX_SPI3_Init();
MX_USART2_UART_Init();
if(HAL_SPI_Receive_DMA(&hspi3, rxSpi, 10) != HAL_OK)
{
Error_Handler();
}
while(HAL_SPI_GetState(&hspi3) != HAL_SPI_STATE_READY){}
while (1)
{
if(HAL_SPI_Transmit(&hspi1, txSpi, 10, 100) != HAL_OK)
{
Error_Handler();
}
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY){}
HAL_Delay(1000);
}
}
If I just send data (receive initialize is commented), on logic analyzer I got this, basically there is missing small interval between two bytes.
HAL_SPI_GetState()
and see what is actually going on. BTW, why do you wait forHAL_SPI_STATE_READY
afterHAL_SPI_Receive_DMA()
? Your SPI receiver is already initialized properly and ready, what you have checked withif
beforeHAL_SPI_Receive_DMA()
. \$\endgroup\$