Skip to main content
Visitor II
January 17, 2022
Question

HAL I2C DMA BUGS Why does this simple DMA code Not Work ???

  • January 17, 2022
  • 12 replies
  • 7108 views

Hello

Having real issues with the I2C DMA HAL code ???

Is it buggy.... very likely from what i'm reading on the web or is there something I am not understanding ??

I'm simply trying to read data back from a i2c flow sensor with minimal interruption to the processor thus why trying to use HAL I2C DMA

when I use use NON DMA I2C code everything is great and works well

HAL_I2C_Master_Receive( &hi2c1, Sensor_Adr << 1 | 0x01, I2C1_DATA , 9, HAL_MAX_DELAY );

0693W00000JMF9cQAH.jpg 

Yet when I use the HAL I2C DMA code its broken ????

HAL_I2C_Master_Receive_DMA( &hi2c1, Sensor_Adr << 1 | 0x01 , I2C1_DATA, 9);

this should work the same way the non DMA code work, but using the DMA hardware, but we can see it does not....

0693W00000JMFBnQAP.jpg 

we can see it starts to initiate a DMA I2C session, but stops after dropping SDA & SCL line why ??????

It should continue to read back the data from the sensor the same way the Non DMA I2C code does. ??

Can someone please help and advise as I am totally lost, what am I missing or is there a bug, thank you in advance for any help

I found this on the internet, not sure if its relevant

I had been struggling with the same problem on STM32F407 and I2C1.

After searching for potential bugs in the program flow, i found out that the function HAL_I2C_Master_Transmit_DMA leads to following line:

dmaxferstatus = HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr, (uint32_t)&hi2c->Instance->DR, hi2c->XferSize);

After the first transfer, this won't return HAL_OK, which is necessary for the transmission to continue.

So my solution was simply abort the previous DMA interrupt in the callback function which is called after the transmission has completed. The same can be implied with HAL_I2C_Master_Receive_DMA. To resolve the problem, i added the following callback functions in main.c:

void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
 
{if (hi2c->Instance==hi2c1.Instance)
 
 {HAL_DMA_Abort_IT(hi2c->hdmatx);
 
 }
 
}
 
 
 
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
 
{if (hi2c->Instance==hi2c1.Instance)
 
 { HAL_DMA_Abort_IT(hi2c->hdmarx);
 
 }
 
}

I have tried adding these interrupt call backs but still does not work ??

can someone please advise a workaround for this bug or let me know what I am doing wrong

thank you for any help

regards

    This topic has been closed for replies.

    12 replies

    Visitor II
    February 17, 2024

    I am going through the exact same problem. any solution to this yet?

    Visitor II
    February 17, 2024

    I have it working by:

     1) Ensuring the I2C event interrupt is enabled in addition to the DMA interrupt (the former wasn't)

    2) By adding HAL_DMA_Abort_IT(hi2c->hdmarx); into the callback as suggested by JHERI

    Visitor II
    March 9, 2024

    blox fruit mod menu auto farm mobile apk is a modified version of the game tailored for mobile devices. It features a mod menu allowing players to access various cheats and enhancements, including auto farming capabilities. However, downloading and using such APKs may violate the game's terms of service and expose users to security risks. Caution should be exercised when interacting with unofficial or modded versions of games.

    Explorer
    November 11, 2024

    //don't forget to activate I2C3 Event/Error Interrupt