cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F405RG HAL_I2C_Mem_Read_DMA stopped after reading 2 bytes.

GChen.5
Associate II

I was trying to read the 24AA64FT EEPROM using the I2C DMA methods. But the I2C read will break after reading 2 bytes for no reason, and both SDA and SCL stay low. As you can see in the picture, the reading starts with writing 0x50 (0xA0 >> 1) to the EEPROM, then it reads 0x30 and 0x78 and it just stops.

Here is the code, my I2C was configured with STM32CubeMX, I enabled the RX DMA and event/error interrupt.

uint8_t pBuff[64];
memset(pBuff, 0, sizeof(pBuff));
uint8_t res;
// HAL_I2C_Mem_Read works fine
// res = HAL_I2C_Mem_Read(&hi2c1, 0xA0, 0, I2C_MEMADD_SIZE_16BIT, pBuff, 64, 100);
// HAL_I2C_Mem_Read_DMA will stop after reading 2 bytes
res = HAL_I2C_Mem_Read_DMA(&hi2c1, 0xA0, 0, I2C_MEMADD_SIZE_16BIT, pBuff, 64);

0693W00000FCZtZQAX.png 

Here is the result for HAL_I2C_Mem_Read, there is no problem.

0693W00000FCZtyQAH.png

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4

Thank you! It is the CubeMX init order problem.

GChen.5
Associate II

I solved the problem by place the DMA init before I2C init.

MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();

I'm using the STM32CubeMX 6.3.0 Linux version. Hope this problem will be fixed in the future.

Hello @GChen.5​ ,

This problem will be fixed in the next release of CubeMx.

Thanks for your contribution.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen