Skip to main content
Jiannong Zhou
Associate III
Apr 11, 2023 1:29 PM UTC
Question

only interrupt once for HAL_SPI_RxCpltCallback

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

This topic has been closed for replies.

2 replies

Bob S
Super User
Apr 11, 2023 4:49 PM UTC

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.

Jiannong Zhou
Associate III
Apr 11, 2023 11:57 PM UTC

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