cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in getting I2C working with 100KHz clock rate

Josh Liu
Associate
Posted on October 03, 2017 at 00:53

Hi, I don't know if anyone has ever encountered the same issue I am encountering. When I set I2C clock rate to 100KHz and use HAL_I2C_Master_Receive command to receive I2C data, the I2C_WaitOnRXNEFlagUntilTimeout function would intermittently return an error even if the data has been successfully received. The reason the I2C_WaitOnRXNEFlagUntilTimeout function returns an error is because STOPF flag is being detected before FXNE flag is being detect. Looking closely at the code in the I2C_WaitOnRXNEFlagUntilTimeout function, I found there is a chance for firmware to detect STOPF flag before it detects FXNE flag, even if FXNE flag is being set before STOPF flag is being set. I don't know if anyone had this issue too.

2 REPLIES 2
Doug Kehn
Senior
Posted on October 17, 2017 at 00:59

Yes, I am observing this issue on STM32F777 using STM32CubeMX v4.1 and STM32CubeF7 v1.8.0.

Other posts, [1]

https://community.st.com/0D50X00009XkhEkSAJ

, and [2]

https://community.st.com/0D50X00009XkfLnSAJ

report similar observation. An ST reply to [2] indicates that the issue was fixed 'in the last STM32CubeF7 version.' (It would be helpful to be explicit when referencing a version.) I believe STM32CubeF7 v1.8.0 is the latest version so should the fix be in this version?

Regards,

...doug

David Littell
Senior III
Posted on October 17, 2017 at 17:50

The HAL gets carried away with 'common code cuteness' and sometimes this is the result.  It looks like I2C_WaitOnRXNEFlagUntilTimeout() tries to serve two masters, Master and Slave receive, and fails due to a race.  HAL_I2C_Mem_Read() appears to get it right.