2023-04-11 06:29 AM
Configured Master/Slave SPI.
(1). trigger Interrupt SPI receive.
(2). Interrupt and receive a data
(3). Trigger interrupt SPI receive again
(4). Never trigger SPI Interrupt receive.
...
HAL_SPI_Receive_IT(&hspi1, SPI_Receive_Buffer, SPI_RECEIVE_DATA_LENGTH);
while (1)
{
if(SPI_Frame_Reveived)
{
SPI_Frame_Reveived = 0;
HAL_SPI_Receive_IT(&hspi1, SPI_Receive_Buffer, SPI_RECEIVE_DATA_LENGTH);
}
}
...
Interrupt:
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
SPI_Frame_Reveived = 1;
}
Why SPI receive IT only once?
Jiannong
2023-04-11 09:49 AM
Did you step through your code in main() and see what happens (or doesn't happen) to SPI_Frame_Received?
How and where do you declare SPI_Frame_Received? I'm guessing something like "int SPI_Frame_Received". It needs to be declared as "volatile", otherwise the code in main() will never see the change made in the callback.
2023-04-11 04:57 PM
Hi Bob S,
thanks for your suggestion.
For SPI_Frame_Reveived, I declared in main()
uint8_t SPI_Frame_Reveived
I will try to declare as "volatile".
And I tried to add the code below in main() loop. it seems that it can be interrrupted.
HAL_SPI_Receive_IT(&hspi1, SPI_Receive_Buffer, SPI_RECEIVE_DATA_LENGTH);
/* Receive command from Master */
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) {}
I do not know why we keep running "HAL_SPI_Receive_IT".
Jiannong