cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 (SPI Receive only Slave Mode) HAL_SPI_Receive_IT () only worked once.

KLim.16
Associate

Hi, I did enable one time HAL_SPI_Receive_IT one time in int main().. after the first spi transaction completely received i did re-enable the spi receive interrupt in callback function..

But the problem is , the HAL_SPI_Receive_IT succesfully receive the correct data in the first time, after that none of it was correct.

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)

{

rxbuf1[0]=rxbuf[0];

rxbuf1[1]=rxbuf[1];

rxbuf1[2]=rxbuf[2];

rxbuf1[3]=rxbuf[3];

rxbuf1[4]=rxbuf[4];

if(HAL_SPI_Receive_IT(&hspi1,(uint8_t*)&rxbuf,5)!= HAL_OK)

{

Error_Handler();

}

}

Is anything i need to do ? for example clear the interrupt flag or what?

It would be much appreciate if you could help.

Thanks.

Regards,

Kelvin

1 REPLY 1
Ozone
Lead

I'm not familiar with Cube/Hal code.

But a common mistake with serial peripherals is not to deal with errors / error flags. In your case probably overflow.

As long as the error condition exists, no rx interrupt is raised, and received characters are lost.

In difference to the rx interrupts, error flags are not reset when reading the rx register. You need to clear the flag manually in the status register.