Skip to main content
GChen.5
Associate II
October 14, 2021
Solved

STM32F405RG HAL_I2C_Mem_Read_DMA stopped after reading 2 bytes.

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

This topic has been closed for replies.
waclawek.jan
waclawek.janBest answer
Super User
October 15, 2021

4 replies

waclawek.jan
waclawek.janBest answer
Super User
October 15, 2021
GChen.5
GChen.5Author
Associate II
October 15, 2021

Thank you! It is the CubeMX init order problem.

GChen.5
GChen.5Author
Associate II
October 15, 2021

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.

ST Technical Moderator
October 15, 2021

Hello @GChen.5​ ,

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

Thanks for your contribution.

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks