cancel
Showing results for 
Search instead for 
Did you mean: 

SPI DMA in slave mode , HAL_SPI_TxRxCpltCallback() callback not being called?

krubow
Associate II

I am using STM32F446RET6 with STM32CubeMX and STM32CubeIDE to create an SPI slave device using SPI1 in DMA mode using the HAL SPI driver. I call HAL_SPI_Receive_DMA() in main to receive 1 byte from the attached SPI master device. It is successful, and I get to the HAL_SPI_RxCpltCallback() function. In that callback function I call HAL_SPI_TransmitReceive_DMA() to exchange 2 bytes of data bidirectionally with the master. It is apparently successful, and I get to the HAL_SPI_TxRxCpltCallback() function. In that callback function I call HAL_SPI_TransmitReceive_DMA() again to transmit a data packet to the master of some length (determined by the previous 2 bytes). Although the master SPI device does generate the correct number of clock pulses, this third data transfer never completes and I never get to the HAL_SPI_TxRxCpltCallback() function again. My programs simply hangs at this point.

I have several questions. First, is it legal to call HAL_SPI_TransmitReceive_DMA() (or HAL_SPI_Transmit_DMA() or HAL_SPI_Receive_DMA()) from within the callback function of a previous SPI DMA transfer? Secondy, I believe there is no activity on the MISO data line after my last call to HAL_SPI_TransmitReceive_DMA(). Why is SPI1 apparently not sending any data although the attached master SPI device is generating clock pulses? The apparent lack of data being transferred seems to be consistent with the failure of the transfer to complete, and the failure of the callback function to be called.

Any ideas about where I might be going wrong would be appreciated.

0 REPLIES 0