← index #2419PR #13281
Likely Duplicate · high · value 2.236
QUERY · ISSUE

I2C bus recovery

openby deshipuopened 2016-09-14updated 2024-09-29
enhancementports

I wonder how useful would it be to add a bus recovery mechanism to the software I2C implementation. It would be something similar to what is discussed here: https://github.com/esp8266/Arduino/issues/1025

The particular use case is when either the slave or the master get reset in the middle of a transmission, and leave the bus in inconsistent state, usually with the other party pulling one of the lines down and preventing communication. This can easily happen when we are doing aggressive power management, entering deep sleep or cutting power to the sensors.

The proposed solution is to strobe the clock line several times and send a NACK, to make sure all the devices on the bus get to finish the last byte they were sending.

CANDIDATE · PULL REQUEST

machine_i2c: Add I2C bus clear support.

closedby PepperoniPinguopened 2023-12-27updated 2025-06-13
extmod

I have some software that is using I2C on the rp2040. Over a couple of months of continuous running there have been some failed transactions resulting in exceptions. Since these are rare, and, the i2c waveform is not too pretty when looked at with an oscilloscope, I presume my hardware implementation is at fault. Nevertheless, since this system is running 24/7 in a critical environment it is essential to be able to recover from these crashes. The proper way to do this is to send an I2C bus clear sequence (a.k.a. software reset) and retry. To do the bus clearing you simply send 10 negative pulses on SCL. This clocks out potential stuck data in the output registers of peripherals.

This PR implements:

  • API backend support for sending an I2C bus clear sequence
    • accessible from python by i2c.clear_bus()
  • said function in the:
    • soft I2C driver
    • rp2 I2C driver

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied