A scanner is a useful witness, but a poor storyteller. It reports addresses that acknowledge a transaction. It cannot prove how many physical chips answered, whether their data is correct, or why a line is held low. This experiment separates those questions on a deliberately simple 3.3 V bus.

Build a bus whose behavior you can explain
I²C means Inter-Integrated Circuit. Its SDA data and SCL clock wires use open-drain signaling: participants pull a line low or release it, while a resistor brings a released wire high. An acknowledgement, abbreviated ACK, is the low response used to accept an address or byte. A missing ACK is evidence about that transaction, not an automatic verdict that a device is dead.
Use an ESP32-DevKitC V4 with ESP32-WROOM-32E and two 24LC256-I/P memories. These exact memories have hardware address straps, making a controlled collision easy to construct. Their write-protect inputs stay high throughout this experiment. The program only scans addresses; it sends no memory data payload. Do not use a bus containing valuable settings or unfamiliar devices for exploratory recovery clocks.
Parts and equipment
- Espressif ESP32-DevKitC V4 with ESP32-WROOM-32E and MicroPython 1.26.0. Use a dedicated low-voltage lab bus with no other controller.
- Two Microchip 24LC256-I/P PDIP-8 memories, two 100 nF capacitors, one pair of 4.7 kΩ bus pullups, one optional 1 kΩ fault-injection resistor and jumper.
Every connection
| Pin or part | Connection and purpose |
|---|---|
| Shared bus | ESP32 GPIO21 → both memory SDA pin 5; GPIO22 → both SCL pin 6. One 4.7 kΩ resistor from each line to ESP32 3V3. |
| Each memory supply | Pin 8 VCC → 3.3 V; pin 4 VSS → common GND; 100 nF directly between 8/4 on each chip. |
| Memory A | A0/A1/A2 pins 1/2/3 → ground: address 0x50. WP pin 7 → 3.3 V. |
| Memory B | Initially A0/A1/A2 → ground: also 0x50. Later, with power off, move only A0 pin 1 to 3.3 V: address becomes 0x51. WP pin 7 → 3.3 V. |
| Optional held-low test | On this isolated open-drain bus only, temporarily connect SDA or SCL to ground through 1 kΩ. Fit/remove with power off. Never force a push-pull output or supply rail this way. |
Start with the electrical idle state
Before creating the software I²C controller, the program configures both pins as open-drain and releases them. At idle both should read high. If SCL is low, the controller cannot create valid high clock periods. If SDA is low with SCL high, a peripheral might be waiting for more clocks, or the wiring might simply be holding the line down. These causes require different follow-up observations.
Each 4.7 kΩ pullup supplies about 0.70 mA into a low line. With the optional 1 kΩ resistor to ground, the static divider predicts about 3.3 × 1/(4.7 + 1) = 0.58 V and 0.58 mA through the series combination. This deliberately models a held-low line on a known open-drain circuit. Do not copy that fault injection onto an unknown push-pull signal, which actively drives high and would fight the load.
What one address really means
With A0, A1 and A2 grounded on both memories, both respond at seven-bit address 0x50. A scan still shows a single entry. The acknowledgement is shared electrically; the scanner does not receive two votes. Two same-address memories containing equal bytes may even appear to read correctly, concealing the problem. Differing data can produce misleading combined behavior, so do not test that by writing important data.
Power down, disconnect memory B completely and scan A alone. Repeat with B alone. If each appears at 0x50, the identity conflict is established by isolation, not by an imaginary collision detector. Power down again, connect both and strap only B’s A0 high. Addresses 0x50 and 0x51 should then be distinguishable. Address straps select a device; they do not change its memory capacity.
Recovery has a stopping rule
NXP’s bus-clear guidance calls for up to nine clocks when SDA is stuck low. SCL held low instead calls for investigating or resetting the devices. Our recover function releases SCL and waits at most about 1 ms for it to rise before proceeding. Every high clock phase is verified. It never actively drives either wire high.
If SDA is released during those clocks, the function forms a STOP condition by allowing SDA to rise while SCL is actually high. If either wire remains stuck, it reports a specific failure and stops. The main program asks you to type CLEAR before attempting this on the isolated lab bus. Recovery is a deliberate experiment because clocks can advance a peripheral’s unfinished transaction; it is not a harmless universal repair button.
Complete program
"""ESP32-DevKitC V4 / MicroPython 1.26.0. Isolated 3.3 V lab bus only."""
def release_wait(pin, pause):
pin.value(1) # OPEN_DRAIN: release, never actively drive high
for _ in range(100):
if pin.value():
return True
pause(10)
return False
def recover(scl, sda, pause):
sda.value(1)
if not release_wait(scl, pause):
return 'SCL STUCK: inspect or reset devices', 0
if sda.value():
return 'IDLE', 0
clocks = 0
for _ in range(9):
scl.value(0); pause(10)
if not release_wait(scl, pause):
return 'SCL STUCK DURING CLEAR', clocks
pause(10); clocks += 1
if sda.value():
break
if not sda.value():
return 'SDA STUCK: inspect or reset devices', clocks
# Form STOP with SDA rising only after released SCL is actually high.
scl.value(0); sda.value(0); pause(10)
if not release_wait(scl, pause):
sda.value(1)
return 'SCL STUCK BEFORE STOP', clocks
pause(10); sda.value(1); pause(10)
return ('CLEARED' if sda.value() else 'SDA STUCK: inspect or reset devices'), clocks
def main():
from machine import Pin, SoftI2C
from time import sleep_us
scl = Pin(22, Pin.OPEN_DRAIN, value=1)
sda = Pin(21, Pin.OPEN_DRAIN, value=1)
print('Idle SCL/SDA:', scl.value(), sda.value())
if not (scl.value() and sda.value()):
if input('Type CLEAR to attempt up to nine clocks on this isolated lab bus: ') != 'CLEAR':
return
result, clocks = recover(scl,sda,sleep_us)
print(result, 'clocks:', clocks)
if result not in ('IDLE','CLEARED'):
return
bus = SoftI2C(scl=scl, sda=sda, freq=100000, timeout=1000)
try:
addresses = bus.scan()
print('7-bit addresses:', [hex(a) for a in addresses])
print('One address is NOT proof of one device. Isolate same-address parts to count them.')
if not addresses:
print('No ACK: check power, address straps and wiring; not proof of a dead chip.')
except OSError as exc:
print('SCAN FAILED; inspect idle levels. No automatic repeated recovery:', exc)
if __name__ == '__main__':
main()
Five observations to reproduce
- Wire one memory, both pullups and common ground with power off. Start the program and record idle levels and the scan list. An expected first result is high/high and 0x50.
- Run the two-device same-address experiment, isolating each device with power disconnected. Change B’s A0 strap and confirm two addresses. Record the physical configuration with every scan.
- Remove both memory devices with power off, retain pullups and restart. High/high with no acknowledged address differs from a stuck-low wire; the empty list is legitimate here.
- Restore the test devices and fit the 1 kΩ SDA-to-ground resistor with power off. Restart, request CLEAR and expect a bounded failure while the resistor holds the line. Remove it with power off; do not expect clock pulses to repair a resistor.
- Repeat using SCL instead of SDA. Expect the SCL-stuck report before recovery clocks. Afterwards restore normal wiring and check a fresh scan.
Know the diagnostic boundary
Software cannot release a solder bridge, repair a missing ground or make an unpowered device obey voltage limits. Removing peripheral power while its bus is still pulled high can also feed it through input protection paths. For this bench exercise, power the entire circuit down before removing devices or moving straps. A production reset strategy must account for the actual power domains.
The code uses MicroPython 1.26.0 SoftI2C, a software implementation with an explicit clock-stretch timeout. It scans once, prints an error if needed and ends. It does not loop indefinitely, reset unrelated hardware or conclude that a successful scan proves a healthy sensor. Address acknowledgement must be followed by the device’s real protocol checks in an application.
Host tests feed the actual recovery function released, temporarily held and permanently held lines, including a clock that stops rising. They validate the stopping rules and open-drain command sequence. This circuit has not been physically tested; electrical thresholds, rise times and real peripheral recovery remain bench observations.
Challenge: why can nine clocks fail even with correct code?
The line may be shorted, the peripheral may need a hardware reset, or its internal state may not match the recoverable case. A bounded failure is a useful result: it tells you to inspect or reset deliberately instead of emitting clocks forever.
Sources and related lessons
- NXP UM10204 I2C-bus specification, bus clear section
- Microchip 24LC256 address and write-protect pins
- Espressif ESP32-DevKitC V4 board guide
- MicroPython 1.26.0 I2C reference
Continue with why a voltage divider drops under load, measuring current through a resistor with a voltmeter, and the interactive circuit lessons.



