cancel
Showing results for 
Search instead for 
Did you mean: 

How to use HAL_SPI_Receive_DMA correctly?

Christian B
Associate II
Posted on June 18, 2018 at 15:00

Hi,

How to use HAL_SPI_Receive_DMA correctly? We need to receive an ongoing data stream via spi. For that we use spi receive with dma. But if we call HAL_SPI_Receive_DMA once before the main loop the HAL_SPI_RxCpltCallback will be called only once with correct data. If we put the function call into the callback it's not working but we don't know why... If we put the function call into the main loop it works with correct data, but is it necessary to call the function so often, most of the time it returns BUSY?  That's the way we use the function right now:

if (spiHandle->State == HAL_SPI_STATE_READY) {

        HAL_StatusTypeDef spiReceiveStatus = HAL_SPI_Receive_DMA(spiHandle, spiBuffer, SPI_BUFFER_SIZE);

    }

Thanks

2 REPLIES 2
Thomas Fischer
Associate II
Posted on June 18, 2018 at 15:44

HAL_SPI_RxCpltCallback is called in interrupt context.

Better to save the received data in another buffer in HAL_SPI_RxCpltCallback and set a flag that receive is complete.

In main loop check for this flag and initiate a new transfer
AMESD
Associate

hi @Christian B​ 

I have the same problem, have you found a solution? if yes, can you please explain to me how you did it.

Thank you in advance for your answer.