cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_Mem_Read_DMA() Locks up the bus

john gassel
Associate III
Posted on July 17, 2017 at 21:12

I've found that if I try to run the HAL_I2C_Mem_Read_DMA() function and communicate with a device with the wrong slave address, it will hang up the I�C bus.  It leaves SCL set to 0 because it doesn't send the stop bit.  I think this is due to a bug in the HAL library.  

I'm using the latest version of the HAL Driver and I find the following code on line 3500 of stm32f4xx_hal_i2c.c:

/* Do not generate a STOP in case of Slave receive non acknowledge during transfer (mean not at the end of transfer) */

if(hi2c->Mode == HAL_I2C_MODE_MASTER)

{

/* Generate Stop */

SET_BIT(hi2c->Instance->CR1,I2C_CR1_STOP);

}

The comment is that it doesn't want to generate a STOP for a slave.  However, it only checks if hi2c->Mode == HAL_I2C_MODE_MASTER, it does not check if mode == MEM.  In my clase, when the slave address is wrong it just finihsed a master write and should send the stop.

The non-DMA function works just fine.

#hal #i2c #stm32f4
2 REPLIES 2
john gassel
Associate III
Posted on July 17, 2017 at 21:18

Changing line 3501 to: 

if((hi2c->Mode == HAL_I2C_MODE_MASTER) || (hi2c->Mode == HAL_I2C_MODE_MEM))

solves my issue.  Can somoene from ST confirm this is a HAL bug?

Tyler Gilbert
Associate II
Posted on February 02, 2018 at 00:35

Hi,

I came across the same issue and the same code change fixed the problem. Thanks for posting. I think this should be fixed in the HAL libraries.