cancel
Showing results for 
Search instead for 
Did you mean: 

I2C error handling

ECost
Associate II

I am developing with STM32F030Cx, using CubeMX for the configuration. The application is basically a simple full cooperative scheduler (no RTOS, no context switching) that calls several "tasks" in a sequence. I am using the blocking functions of the HAL I2C driver.

STM32 I2C will work in master mode only.

I would like some directions on how to handle the communication errors (BERR, ARLO, timeout etc.) or to reference material such as a flow chart or source code of a library or RTOS.

Maybe the handling of these errors is simple and it is only a matter of following the reference manual, but while researching for questions/answers on the subject, I saw some messages on the I2C channel hanging when a BERR occurred and the fix required some workarounds. So, I would appreciate some advice on how to do to guarantee my application is capable of self recovering when some of these errors occur.

Thanks in advance.

12 REPLIES 12
ECost
Associate II

As a follow-up, I have implemented a recovery routine based on your suggestions above, along with some tips of answers in the link below:

https://electronics.stackexchange.com/questions/267972/i2c-busy-flag-strange-behaviour

In the end I disable the I2C interface using HAL_I2C_DeInit, perform the bus reset and restart the I2C using HAL_I2C_Init.

I have set a second Discovery to inject errors on the I2C bus. The error gen inject pulses on SDA and SCL at regular intervals while the main routine reads the slave continuously. I monitor the bus activity with the protocol analyzer and the errors are displayed. When a timeout is detected, the recovery routine is called. I left it running overnight and after around 12 million iterations it recovered from more than 500k timeouts and 13k AF errors. These were the errors I observed when I used the tweezers to inject errors.

Thank you for your help.

As it is not true if it does not have a picture... :grinning_face:

0690X00000BwNxLQAV.jpg

toroid
Associate III

For my application, HAL_I2C_DeInit and HAL_I2C_Init worked fine as I2C error handler.

Toroid, thank you for your suggestion.