Study I2C modules and their protocol for multi-device communication over a two-wire serial bus in electronics.
Connecting many sensors, memories, and displays to a microcontroller using only two wires is the advantage of the I²C (*Inter-Integrated Circuit*) bus. It was developed by Philips in 1982 as a communication system between integrated circuits within a device, and it is today one of the most widely used buses for connecting slow or medium-speed peripherals on the same board [1][2][3][4].
The bus has two bidirectional lines.
- SDA: data (*Serial Data*).
- SCL: clock (*Serial Clock*), generated by the device controlling the bus, the master.
Both are open-collector (or open-drain): each device can only pull the line low by connecting it to ground, but cannot drive it high. The high level is imposed by a pull-up resistor to the supply voltage, one for each line. When no device pulls the line low, it rises to a high level: the line is a wired AND of all devices. This structure allows multiple masters to share the bus without short circuits [1][2][3].
Each device has an address of $7$ bits (in some extensions $10$), for a maximum of $128$ addresses, of which about $112$ are usable. Communication proceeds as follows.
1. The master generates the start condition: it pulls SDA low while SCL is high.
2. It sends the $7$-bit address and a direction bit ($0$ write, $1$ read).
3. The device with that address responds with an ACK acknowledgment bit (pulling SDA low on the ninth clock pulse).
4. Data bytes are exchanged, each followed by an ACK from the receiver.
5. The master generates the stop condition: it releases SDA to high while SCL is high.
Data on the SDA line can change only when SCL is low, and must remain stable while SCL is high: the only exceptions are start and stop [1][2][3].
The standardized modes are standard ($100\ \mathrm{kbit/s}$), fast ($400\ \mathrm{kbit/s}$), fast-plus ($1\ \mathrm{Mbit/s}$), and high-speed ($3.4\ \mathrm{Mbit/s}$). They are slower than SPI, and the protocol has lower efficiency, because for each data byte nine bits are transmitted with the ACK, plus address and start and stop conditions [1][2][4].
The line rises slowly after release, with time constant $R_p C_b$, where $C_b$ is the total bus capacitance (wires and device inputs, maximum $400\ \mathrm{pF}$). The rise time between $30\ \%$ and $70\ \%$ of the supply voltage is $t_r = 0.8473\,R_p\,C_b$, and the standard limits it to $1000\ \mathrm{ns}$ in standard mode and to $300\ \mathrm{ns}$ in fast mode. This results in a maximum resistor value, $R_{p,max} = t_r/(0.8473\,C_b)$. The minimum value is set by the current the device can sink (usually $3\ \mathrm{mA}$ with maximum low level $0.4\ \mathrm{V}$): $R_{p,min} = (V_{cc} - 0.4)/3\ \mathrm{mA}$ [1][2][3].
A slow slave can hold SCL low after each bit (clock stretching), forcing the master to wait until it is ready. In a multi-master system, if two masters start simultaneously, each reads SDA while transmitting: the one that sees a level different from what it sent loses arbitration and leaves the bus, without data loss [1][2].
The ideal bus has instantaneous edges. In practice, the capacitances of wires and devices limit speed and length (from a few centimeters to a few meters), an excessively large pull-up slows edges and causes errors, while one that is too small overloads the drivers. Two devices with the same address cannot be on the same bus (this is solved with configurable addresses or a bus multiplexer). Device voltage levels must be made compatible with a level shifter.
A bus with power supply $3.3\ \mathrm{V}$, capacitance $C_b = 200\ \mathrm{pF}$ at $100\ \mathrm{kHz}$ and capacitance $100\ \mathrm{pF}$ at $400\ \mathrm{kHz}$ (assumed values).
1. Minimum resistor: $(3.3 - 0.4)/0.003 = 967\ \Omega$.
2. Maximum resistor in standard mode: $1000\ \mathrm{ns}/(0{,}8473\cdot200\ \mathrm{pF}) = 5{,}9\ \mathrm{k\Omega}$; a normalized value of $4{,}7\ \mathrm{k\Omega}$ is chosen, with a rise time of $0{,}8473\cdot4700\cdot200\cdot10^{-12} = 0{,}80\ \mathrm{\mu s}$.
3. Maximum resistor in fast mode, with $100\ \mathrm{pF}$: $300\ \mathrm{ns}/(0{,}8473\cdot100\ \mathrm{pF}) = 3{,}5\ \mathrm{k\Omega}$; $2{,}2\ \mathrm{k\Omega}$ is chosen, with a rise time of $186\ \mathrm{ns}$.
4. Writing two bytes to a device register: address with direction bit, register address, and two data bytes are $4$ bytes, i.e. $36$ bits including ACKs, plus start and stop (about $2$ clock periods): approximately $38$ periods, equal to $0.38\ \mathrm{ms}$ at $100\ \mathrm{kHz}$ and to $95\ \mathrm{\mu s}$ at $400\ \mathrm{kHz}$. The useful data only ($16$ bits) occupy less than half the time.
I²C is used for temperature, pressure, and inertial sensors, real-time clocks, EEPROM memories, converters, character OLED and LCD displays, port expanders, battery and power controls, and for module management in computers and phones.
[1] Wikipedia (it): I²C
[2] Wikipedia (en): I²C
[3] Wikipedia (de): I²C
[4] Wikipedia (fr): I2C
Generating summary…