AnsweredAssumed Answered

STM32F091RC I2C DMA transfer complete 

Question asked by Youssouf Coulibaly on Jul 6, 2017
Latest reply on Jul 7, 2017 by Youssouf Coulibaly

Hello everybody,

 

I am using I2C interface in master mode to collect data from external slave device with DMA in non-blocking mode.

- HAL_I2C_Master_Transmit_DMA

- HAL_I2C_Master_Receive_DMA

My program is working fine since I get correct data.

 

BUT I would like to get an event that the exchanges are completed by registering these functions during INIT step :

-  // HAL Register DMA Tx Transfer events
 HAL_DMA_RegisterCallback(dmaHandleTx, HAL_DMA_XFER_CPLT_CB_ID, i2cTransmitFullCallback)

- // HAL Register DMA Rx Transfer events
 HAL_DMA_RegisterCallback(dmaHandleRx, HAL_DMA_XFER_CPLT_CB_ID, i2cReceiveFullCallback)

 

When I run my program, I get DMA interrupt in below function but no callback call is triggered. 

void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler(void)
{
   HAL_DMA_IRQHandler(dmaHandleTx);
   HAL_DMA_IRQHandler(dmaHandleRx);
}

 

I tried to look carefully inside the HAL itself and I found something quite strange from my understanding.

HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size)
{
      /* Set the I2C DMA transfer complete callback */
      hi2c->hdmatx->XferCpltCallback = I2C_DMAMasterTransmitCplt;

      /* Set the DMA error callback */
      hi2c->hdmatx->XferErrorCallback = I2C_DMAError;

      /* Set the unused DMA callbacks to NULL */
      hi2c->hdmatx->XferHalfCpltCallback = NULL;
      hi2c->hdmatx->XferAbortCallback = NULL;

      /* Enable the DMA channel */
      HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)pData, (uint32_t)&hi2c->Instance->TXDR, hi2c->XferSize);

}

If the Callback function pointer is initialize at each call of HAL_I2C_Master_Transmit_DMA function with internal I2C_DMAMasterTransmitCplt, how it manages my registered callback in INIT step (i2cTransmitFullCallback) ?

 

Does anyone has an idea about this ?

 

Thanks a lot.

Outcomes