I2C Bus Explained: The Two-Wire Protocol for Embedded Systems
The I2C (Inter-Integrated Circuit) bus is one of the most widely used communication protocols in embedded systems. Designed for simplicity and efficiency, it allows a microcontroller to communicate with multiple peripherals using just two wires.
โก Physical Topology: Open-Drain Simplicity #
I2C minimizes wiring by using a shared bus architecture:
- SDA (Serial Data Line): Transfers data
- SCL (Serial Clock Line): Synchronizes communication
- Pull-up Resistors: Required to define logic HIGH (open-drain cannot drive HIGH)
Key Characteristics #
| Feature | Description |
|---|---|
| Open-Drain Design | Devices can only pull lines LOW; HIGH is via pull-ups |
| Bus Capacitance | Limited to 400pF (short distance communication) |
| Addressing | 7-bit (common) or 10-bit device addressing |
Without proper pull-ups, the bus will failโsignals will never reach a valid HIGH level.
๐ Signaling Rules: START, STOP, and Data Validity #
I2C communication is defined by how SDA behaves relative to SCL:
- Data Validity: SDA must remain stable when SCL is HIGH
- START Condition: SDA transitions HIGH โ LOW while SCL is HIGH
- STOP Condition: SDA transitions LOW โ HIGH while SCL is HIGH
These transitions define the boundaries of every transaction.
๐ฆ Data Frame Structure: Bytes + ACK #
All I2C data transfers follow a strict structure:
-
Address Frame
- 7-bit slave address
- 1-bit R/W flag (0 = Write, 1 = Read)
-
Data Bytes
- Transmitted MSB first
- Always 8 bits per byte
-
ACK/NACK Bit (9th Clock)
- ACK (0): Receiver confirms success
- NACK (1): Error, buffer full, or end of read
Key Insight #
Every byte requires acknowledgmentโthis ensures reliable communication even on noisy lines.
๐ Common Transaction Patterns #
๐ Master Write #
- Master sends START
- Sends address + Write bit
- Slave ACKs
- Master sends data bytes
๐ Master Read #
- Master sends START
- Sends address + Read bit
- Slave transmits data
- Master ACKs each byte (NACK on last byte)
๐ Combined Format (Repeated START) #
Used for register access:
- Write register address
- Issue Repeated START
- Switch to Read mode
Advantage: Prevents bus release in multi-master systems and improves efficiency.
๐ Speed Modes #
| Mode | Max Speed | Typical Use |
|---|---|---|
| Standard Mode | 100 kbit/s | Basic sensors |
| Fast Mode | 400 kbit/s | Displays, modern peripherals |
| High-Speed Mode | 3.4 Mbit/s | High-performance devices |
Higher speeds require tighter control over signal integrity and pull-up sizing.
๐ ๏ธ Debugging & Design Tips #
-
Pull-Up Resistors Matter
- Too large โ slow rise time โ signal corruption
- Typical values:
- 100kHz: ~4.7kฮฉโ10kฮฉ
- 400kHz: ~2.2kฮฉโ4.7kฮฉ
-
Watch Bus Capacitance
- Long traces or cables degrade signal quality
-
Avoid Address Conflicts
- Use configurable address pins where possible
-
Use Logic Analyzers
- Essential for visualizing START/STOP and ACK behavior
๐งฉ Summary #
I2C remains the go-to protocol for low-speed, short-distance communication thanks to its simplicity and flexibility. By understanding its open-drain nature, strict signaling rules, and acknowledgment system, you can design robust and efficient embedded systems.
Master the fundamentalsโand most I2C bugs become predictable and easy to fix.