cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_RxCpltCallback not being called after HAL_SPI_Receive_IT is being completed

IHACH.1
Associate II

hi,

I'm new in ST. I'm trying to implement SPI communication between FPGA and STM32L051R8T6 (slave).

I've initialized the spi bus in main (HAL_SPI_Init()), so that it is set to use (HAL_SPI_RxCpltCallback).

and from main i called HAL_SPI_Receive_IT (to recieve 2 bytes).

I am expecting that after the 2 bytes recive HAL_SPI_RxCpltCallback will be called and i could transmit back the data. however HAL_SPI_RxCpltCallback is not being called and it just complete the function and return to main

has anyone encountered this scenario before and could assist?

5 REPLIES 5

Hi. Did you enable interrupt for SPI?

Share your project.

IHACH.1
Associate II

what do you mean enable interrupt  for SPI? i defined the spi ports using cube

IHACH.1
Associate II

should i done an additional setting to enable it?

berendi
Principal

In a previous post you mention that the MCU is running at 32 MHz, and SPI clock is 2 MHz.

It means that receiving one bit takes 500 ns, one byte takes 4 ms, which is 128 system clock cycles.

The HAL interrupt handler is not fast enough to process data at this speed.

Note that the STM32CubeL0 example projects set SPI clock to 125 kHz, i.e. 16 times slower.

Of course there are a lot of other stuff that can go wrong. Check that the interrupt handler (not the callback) is actually called, whether 0,1,2 bytes of the input buffer are changed.

Check SPI register values against the reference manual, assume neither that CubeMX generates correct code not that HAL functions work as you expect them to work.

IHACH.1
Associate II

thanks.

  1. whether 0,1,2 bytes of the input buffer are changed
  2.  interrupt handler (not the callback) is called
  3. but again the callback is not called