Skip to main content
Arman Ilmak
Senior
March 15, 2021
Question

HAL_I2C_Mem_Read_DMA problem

  • March 15, 2021
  • 2 replies
  • 1103 views

Hey guys.

Im using cubemx for i2c initiallization and i have a problem while using this HAL_I2C_Mem_Read_DMA function.

When i call it in while(1) it works one time and after that it returns error or busy.

 while (1)
 {
		HAL_Delay(1000);
		HAL_I2C_Mem_Read_DMA(&hi2c1,0x68<<1,0x00,I2C_MEMADD_SIZE_8BIT,buf,3);
		HAL_Delay(1000);
 
 }

This topic has been closed for replies.

2 replies

ST Technical Moderator
March 16, 2021

Hello @Arman Ilmak​ ,

I would suggest you adding more details to your post: Which Cube MCU package and version are you using ? Which CubeMX version ?

Could you please share your .ioc to check with you this case ?

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
Lecordier.Guy
Associate III
March 19, 2021

Hello,

I have a similar problem with STM32F4Cube V1.26.0

I use HAL_I2C_Mem_Read_DMA() & HAL_I2C_Mem_Write_DMA()

The 1st time HAL_I2C_Mem_Write_DMA is used, it sends 2 extra bytes

The next time, it sends the correct count.

I think it is due to the EventCount and MemaddSize which are not initialized and adjusted when DMA is used.

The 1st time, EventCount & MemaddSize are 0, so the I2C_MemoryTransmit_TXE_BTF() sends the 2 extra bytes.

The next time it is called, EventCount stays at 2, so the I2C_MemoryTransmit_TXE_BTF() generates only the Stop.  

I modified HAL_I2C_Mem_Read_DMA() & HAL_I2C_Mem_Write_DMA() in stm32f4xx_hal_i2c.c

   /* Prepare transfer parameters */

   hi2c->pBuffPtr   = pData;

   hi2c->XferCount  = Size;

   hi2c->XferSize   = hi2c->XferCount;

   hi2c->XferOptions = I2C_NO_OPTION_FRAME;

   hi2c->Devaddress = DevAddress; << new

   hi2c->Memaddress = MemAddress; << new  

   hi2c->MemaddSize = MemAddSize; << new

   hi2c->EventCount = 0U;         << new

  

       /* Send Slave Address and Memory Address */

       if (I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, I2C_TIMEOUT_FLAG, tickstart) != HAL_OK)

       {

         /* Abort the ongoing DMA */

...........

}

       hi2c->EventCount = 2U; << New

Regards,