2020-01-15 10:56 AM
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.
2020-01-23 04:12 AM
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:
2021-05-31 04:32 AM
For my application, HAL_I2C_DeInit and HAL_I2C_Init worked fine as I2C error handler.
2021-08-12 04:42 AM
Toroid, thank you for your suggestion.