Skip to main content
Associate II
June 3, 2024
Solved

HAL_I2C_Mem_Write_DMA issue

  • June 3, 2024
  • 6 replies
  • 2614 views

Hi There,

I have searched a lot about the  HAL_I2C_Mem_Write_DMA problem and seems like i have not found anywhere else this issue has been solved.

Can anyone contribute if someone has solved it.

 

Thanks

This topic has been closed for replies.
Best answer by Ganesh-K-Grg

Hi Andrew,

I found the solution from this link:-

https://community.st.com/t5/stm32-mcus-products/hal-i2c-dma-bugs-why-does-this-simple-dma-code-not-work/td-p/136667

 

I need to add below code and enable the I2c event interrupt. Seems working fine. But I need to tune my code a little bit more.

 

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

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

 

 

6 replies

Andrew Neil
Super User
June 3, 2024

@Ganesh-K-Grg wrote:

the  HAL_I2C_Mem_Write_DMA problem


what problem?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
June 4, 2024

Hi Evangelist,

Calling a write function to write about 6 bytes. But it keeps sending contineously a lot of data.

HAL_StatusTypeDef ret = HAL_I2C_Mem_Write_DMA(&hi2c1, (20 << 1) | 0, 4, 1, &to_reg[0], 6);

 

GaneshKGrg_0-1717490730993.png

 

Andrew Neil
Super User
June 4, 2024

Does it work without DMA - ie, using HAL_I2C_Mem_Write ?

Please show a minimum but complete example which illustrates the problem.

What slave device are you using? Show your schematic of how it's connected.

Are you getting ACKs from the slave?

 

Please use this button to properly post source code:

AndrewNeil_0-1717493634578.png

 

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.