Sub topic 2
Two Wires: SDA, SCL, and Open-Drain Lines
Assume you know Arduino setup() and loop(), can use the Serial Monitor, and understand voltage, current, and resistors. You should also be comfortable reading binary and hexadecimal values.
The two shared wires
I2C uses two signal wires:
- SDA is the serial data line. It carries address, command, and data bits.
- SCL is the serial clock line. The controller uses clock pulses to coordinate each bit.
All devices connect to the same SDA and SCL wires. The bus also needs a shared ground. A controller starts transactions, and target devices respond at their assigned addresses.
The wires have two logical states:
| Bus state | Electrical state | Meaning |
|---|---|---|
| High | No device pulls the line down | Logic 1 or bus idle |
| Low | At least one device pulls the line down | Logic 0 |
Why the lines are open-drain
I2C devices normally do not drive SDA or SCL high. Instead, each device can either:
- Pull a line down to ground.
- Release the line and stop driving it.
This arrangement is called open-drain. On some microcontrollers, the equivalent output is called open-collector.
A pull-up resistor connects each line to the bus supply voltage. When every device releases a line, the resistor pulls it high. When any device pulls the line low, the line becomes low. Several devices can therefore share the same wires without directly fighting one another.
Pull-up resistors
Without pull-ups, a released line has no defined high voltage. It can float, causing random readings or a bus that appears permanently low.
The resistor value affects the signal:
- A lower value creates faster rising edges but draws more current when the line is low.
- A higher value reduces current but makes the rising edge slower.
- Long wires and many devices add capacitance, which also slows the rising edge.
Common breakout boards already include pull-ups. If several boards are connected, their resistors work in parallel. The combined resistance may become too low. Check the board documentation before adding another pair.
What happens on the bus
The bus is idle when both lines are high. A transaction begins when SDA changes from high to low while SCL remains high. This is the START condition. A transaction ends when SDA changes from low to high while SCL is high, creating a STOP condition.
During ordinary data transfer, SDA should change while SCL is low and remain stable while SCL is high. The receiver samples the bit during the high part of the clock pulse.
Because any device can pull SCL low, a target can briefly hold the clock low when it needs more time. This behavior is called clock stretching.
Exercise
Why does an I2C device release SDA to send a logic 1 instead of actively driving it high?
Show answer
Releasing the line lets the shared pull-up resistor raise it. Another device can still pull the line low without creating a direct high-to-low output conflict.