I2C Protocol Explained: How Two Wires Talk to Dozens of Chips
One clock line, one data line, and two pull-up resistors let a single microcontroller address up to 112 sensors and displays. How open-drain frames, ACK bits, and pull-up math actually work.
For Readers who have wired sensors to a microcontroller and know basic bits, bytes, and resistors.
A simpler explanation with fewer formulas.
Unlike UART, which connects only two devices point to point, I2C is a shared multi-device bus. Wire SDA (data), SCL (clock), and GND across a whole row of sensors and displays, add two pull-up resistors to your supply voltage (typically 4.7 kΩ), and one microcontroller can talk to dozens of parts without burning extra GPIO pins.
I2C (Inter-Integrated Circuit) is a synchronous, half-duplex, multi-device serial bus that runs over just two wires: SDA (Serial Data) and SCL (Serial Clock). One or more controllers (called masters in older datasheets) drive the clock and initiate transfers, while targets (formerly slaves) answer when addressed.
Because every chip shares the same two copper traces, I2C relies on a clever electrical rule — open-drain outputs with pull-up resistors — so two devices can never short-circuit each other.
At 400 kHz (300 ns rise limit), 4.7 kΩ rounds the rising edge past spec — lower Rₚ to 2.2 kΩ–3.3 kΩ to sharpen it. Pick 0x55 to watch a NACK.
Open-drain wires: why chips never fight
Every SDA and SCL pin on an I2C bus is open-drain: its internal transistor can pull the line LOW to GND, or release it to float high-impedance. External pull-up resistors tied to V_DD bring both lines HIGH whenever every device releases them.
That creates a wired-AND bus: the line is HIGH only if all devices release it, and LOW if any device pulls it down. Two chips speaking simultaneously can never cause a V_DD-to-GND short.
Pull-up resistor sizing is a trade-off between two hard limits from NXP UM10204. Too small a resistor forces the pin’s MOSFET to sink too much current to reach a valid logic LOW (V_OL ≤ 0.4 V at I_OL = 3 mA in Standard and Fast modes):
At V_DD = 3.3 V, R_p(min) ≈ (3.3 − 0.4) / 0.003 ≈ 967 Ω. Too large a resistor combines with total bus capacitance C_b (traces plus device pins) to slow the rising edge past the spec’s maximum rise time t_r (measured from 30% to 70% of V_DD, where ln(7/3) ≈ 0.8473):
In Fast-mode (400 kHz, t_r ≤ 300 ns) on a 100 pF bus, R_p(max) ≈ 3.54 kΩ — so a lazy 10 kΩ pull-up produces rounded shark-fin edges that fail at 400 kHz.
Anatomy of an I2C transfer
During normal data bits, SDA may change only while SCL is LOW and is sampled while SCL is HIGH. START (S) and STOP (P) are the two legal exceptions:
- START (S): SDA falls HIGH → LOW while SCL is HIGH.
- Address byte (MSB first): 7-bit target address (A6…A0) followed by the R/W bit (
0= Write,1= Read). Out of 128 possible 7-bit values (0x00–0x7F), 16 are reserved, leaving 112 usable addresses (0x08–0x77). - ACK / NACK (9th clock pulse): the sender releases SDA. The receiver pulls SDA LOW for ACK (
0), or leaves it HIGH for NACK (1— no matching device, target busy, or end of read). - Data bytes (MSB first): each 8-bit byte is followed by an ACK/NACK bit — 9 clock pulses per byte.
- STOP (P): SDA rises LOW → HIGH while SCL is HIGH, returning the bus to idle.
To read a specific register inside a sensor, the controller uses a Repeated START: it sends START, the sensor’s address with Write (0), and the register number — then immediately sends another START (with no STOP in between), the same address with Read (1), and clocks in the sensor’s reply.
A Repeated START (Sr) lets the controller reverse direction — writing a register pointer and immediately reading back its bytes — without releasing the bus between phases, preventing another controller from claiming the bus mid-transaction.
Speed modes and bus limits
I2C trades raw speed for pin economy and simple wiring. Most microcontroller sensors run in Standard or Fast mode:
| Mode | Max clock | Max bus capacitance C_b | Max rise time t_r | Typical pull-up (3.3 V) |
|---|---|---|---|---|
| Standard-mode (Sm) | 100 kHz | 400 pF | 1000 ns | 4.7 kΩ |
| Fast-mode (Fm) | 400 kHz | 400 pF | 300 ns | 2.2 kΩ |
| Fast-mode Plus (Fm+) | 1 MHz | 550 pF | 120 ns | ~1 kΩ (higher sink driver) |
| High-speed (Hs-mode) | 3.4 MHz | 100–400 pF | 40–80 ns | Active current source |
Real-world quirks: stretching, arbitration, and stuck buses
Two practical traps catch almost every builder at least once:
- 7-bit vs. 8-bit addresses: some datasheets print a chip’s 7-bit address (for example
0x48), while others shift it left by one bit and print the 8-bit write/read pair (0x90/0x91). If your chip answers with NACK, check whether your library expects the 7-bit value. - Too many pull-ups in parallel: many breakout boards already solder 4.7 kΩ or 10 kΩ pull-up resistors onto SDA and SCL. Chain five breakout boards on one bus and their resistors sit in parallel — dropping total resistance below 1 kΩ and preventing chips from pulling the line cleanly to zero.
- Clock stretching: if a target needs extra microseconds to prepare data, it can hold SCL LOW after a byte. A spec-compliant controller must read back SCL and wait until it actually goes HIGH before clocking the next bit.
- Multi-controller arbitration: because SDA is wired-AND, two controllers that issue START simultaneously simply transmit and monitor SDA bit by bit. The first controller that releases SDA (
1) while sensing0on the bus knows another controller pulled it low — and immediately backs off without corrupting the winning frame.