cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Mem_Write_DMA issue

Ganesh-K-Grg
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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);
	}
}

 

 

View solution in original post

6 REPLIES 6
Andrew Neil
Evangelist III

@Ganesh-K-Grg wrote:

the  HAL_I2C_Mem_Write_DMA problem


what problem?

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

 

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

 

 

Hi There,

Yes HAL_I2C_Mem_Write works for me.

I removed the I2C pins from the .ioc file and added back again without renaming the label name on SDA and SCL.

Now i can see that it can send exactly the 6 bytes. But looks like there is no NACK and SCL is pulling low. Iam connecting to RM3100 device.

GaneshKGrg_0-1717496637372.png

 

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);
	}
}

 

 


@Ganesh-K-Grg wrote:

I found the solution 


Excellent - please mark your post as the solution.

https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256