2025-11-21 2:28 AM - last edited on 2025-11-21 3:10 AM by Andrew Neil
I’m working on a project with an STM32F4 microcontroller and using the I2C bus to connect multiple sensors. Everything works initially, but after some time the communication becomes unstable, returning random values or causing the I2C bus to hang. I have tried lowering the clock speed and checking pull-up resistors, but the issue persists.
Has anyone experienced similar issues with I2C on STM32F4 or found a recommended configuration or hardware fix?
Any guidance or examples would be greatly appreciated. Thanks!
2025-11-21 2:53 AM
I would check the bus signal first. With multiple slaves and and long lines, reducing pull-up resistance values might help.
Make sure you have no duplicate addresses on the bus, although I suspect this would manifest quite quickly.
> ... returning random values or causing the I2C bus to hang.
This sounds more like a signal quality issue.
The bus usually "hangs" when a device does not see one or more SCLK impulses, and thus is stuck in a transmission.
If possible add some instrumentation code, attach a scope (2-channel), and try to trigger on such a "hang" event. Alternatively a logic analyser, but those give no indication of signal quality.