2017-07-17 12:12 PM
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 #stm32f42017-07-17 12:18 PM
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?
2018-02-01 03:35 PM
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.