Issues with HAL_SPI_TransmitReceive_DMA
Hi all--
I am using HAL_SPI_TransmitReceive_DMA to retrieve data periodically from an inertial sensor. I receive an EXTI interrupt when the sensor indicates that data is ready, and in response to this I call HAL_SPI_TransmitReceive_DMA to retrieve 15 bytes of data from the sensor, as follows:
HAL_StatusTypeDef res;
/* Register address with read flag */
dataBuf[0] = LSM6DS3H_OUT_TEMP_L_REG | 0x80;
/* Begin data transfer */
CS_LOW();
res = HAL_SPI_TransmitReceive_DMA(&hspi1, dataBuf, dataBuf, 15);In response to HAL_SPI_TxRxCpltCallback, I complete the transfer:
CS_HIGH();
/* Translate the contents of dataBuf here */However, once in a while, when I receive the signal from the sensor, I go to retrieve data only to have HAL_SPI_TransmitReceive_DMA return HAL_BUSY.
Looking into this, I noticed that HAL_SPI_TxRxCpltCallback is not being called. In fact, if I chase this all the way back to HAL_DMA_IRQHandler, I see that the IRQ handler is never called to indicate that the transfer is complete.
Looking into it a little further, I had a look at the DMA state just before the failed call to HAL_SPI_TransmitReceive_DMA. This showed me:
- hspi1.hdmarx->Instance->CNDTR is equal to 1
- hspi1.hdmatx->Instance->CNDTR is equal to 0
This strikes me as really odd. Under normal conditions, both of these are equal to 0 when the transfer is complete. Since the processor is generating the SPI clock, it's not clear to me how the transmitted and received byte counts could be different.
I am using an STM32WB55RG processor and STM32Cube_FW_WB_V1.8.0.
Does anyone have an ideas? Thanks for any help you can offer!
