I2C Communication Explained: A Complete Guide

I2C (Inter-Integrated Circuit, pronounced “I-squared-C” or “I-two-C”) is a synchronous, multi-master, multi-slave serial communication bus protocol developed by Philips Semiconductors (now NXP Semiconductors) in the early 1980s. Designed for short-distance, low-speed communication between integrated circuits (ICs) on a single printed circuit board (PCB), I2C is widely used in embedded systems, consumer electronics, and industrial devices. It uses just two bidirectional wires for data transfer and clock synchronization, making it a simple, cost-effective solution for connecting peripheral devices (e.g., sensors, EEPROMs, displays) to microcontrollers (MCUs).

Unlike other serial protocols (e.g., SPI, UART), I2C supports multiple master devices and addressable slave devices on the same bus, with no need for separate chip select lines.


Core Technical Specifications

I2C defines the physical layer (PHY) and data link layer specifications for serial communication, with key parameters standardized by the I2C Bus Specification (currently Version 7.0, 2021):

ParameterSpecification
Bus WiresTwo bidirectional lines:- SDA (Serial Data): Transmits/receives data- SCL (Serial Clock): Carries the clock signal (generated by the master)
Voltage LevelsTypically 3.3V or 5V (logic levels); some low-power variants support 1.8V
Data Rates– Standard-mode (Sm): 100 kbps- Fast-mode (Fm): 400 kbps- Fast-mode Plus (Fm+): 1 Mbps- High-speed mode (Hs-mode): 3.4 Mbps- Ultra-fast mode (UFm): 5 Mbps
Number of NodesLimited by bus capacitance (max 400 pF); typically up to 10–15 devices (or more with bus extenders)
Addressing7-bit (128 unique addresses) or 10-bit (1024 unique addresses) slave addressing; master devices use dynamic arbitration
TopologyMulti-drop bus (all devices connected to SDA/SCL lines)
Pull-Up ResistorsRequired on SDA and SCL lines (typically 2.2kΩ–10kΩ, depending on voltage and bus speed)
Max DistanceShort-range (typically <1 meter on a PCB; up to 10 meters with twisted-pair cable and transceivers)
Error HandlingAcknowledge (ACK)/Not Acknowledge (NACK) bits for data validation; bus arbitration for master conflicts

Note: The 400 pF bus capacitance limit is a critical constraint—adding too many devices or long wires increases capacitance, reducing maximum data rate and signal integrity.


Key Architectural Features

1. Two-Wire Interface

The minimal two-wire design (SDA + SCL) is the defining feature of I2C, reducing PCB wiring complexity and component count compared to multi-wire protocols like SPI (which requires separate MOSI/MISO/SCLK/CS lines). Both lines are open-drain (or open-collector) outputs, meaning devices pull the line low to transmit a logic 0, and release it to let the pull-up resistors pull the line high (logic 1).

2. Multi-Master/Multi-Slave Support

  • Multi-Slave: Each slave device on the bus has a unique 7-bit or 10-bit address. The master addresses a specific slave for data transmission/reception, enabling communication with multiple peripherals on a single bus (e.g., a temperature sensor, EEPROM, and OLED display connected to one MCU).
  • Multi-Master: Multiple master devices (e.g., two MCUs) can control the bus. If two masters attempt to transmit simultaneously, bus arbitration ensures the master with the higher-priority address (lower binary value) gains control without data corruption.

3. Synchronous Communication

I2C is a synchronous protocol, meaning data transfer is synchronized to the clock signal (SCL) generated by the master. The master controls the clock speed (up to the maximum supported rate of the slowest device on the bus) and initiates/terminates all communication sessions.

4. ACK/NACK Handshaking

After each byte of data is transmitted (8 bits), the receiving device sends an acknowledge (ACK) bit (pulls SDA low) to confirm successful reception, or a not acknowledge (NACK) bit (leaves SDA high) to indicate an error or end of transmission. This handshaking mechanism ensures reliable data transfer.


I2C Communication Process

All I2C communication is initiated and controlled by a master device, following a fixed frame format:

  1. Start ConditionThe master pulls SDA low while SCL is high to signal the start of a communication session. All slave devices on the bus detect this condition and listen for their address.
  2. Slave Address + Read/Write BitThe master transmits a 7-bit slave address followed by a 1-bit read/write (R/W) command:
    • 0 = Master writes data to the slave
    • 1 = Master reads data from the slaveThe addressed slave responds with an ACK bit to confirm it has been selected.
  3. Data Transmission
    • Write Operation: The master sends 8-bit data bytes to the slave, each followed by an ACK from the slave.
    • Read Operation: The slave sends 8-bit data bytes to the master, each followed by an ACK from the master (except the final byte, where the master sends a NACK to end reading).
  4. Stop ConditionThe master releases SDA to go high while SCL is high to signal the end of the session. The bus returns to the idle state (SDA and SCL high via pull-up resistors).

I2C vs. Other Serial Protocols

I2C is often compared to SPI and UART, with distinct tradeoffs for different embedded applications:

CharacteristicI2CSPIUART
Wires2 (SDA/SCL)3–4 (MOSI/MISO/SCLK/CS)2 (TX/RX)
TopologyMulti-master/multi-slaveSingle-master/multi-slavePoint-to-point (typically)
Addressing7/10-bit slave addressesChip select (CS) linesNone (peer-to-peer)
Data RateUp to 5 Mbps (UFm)Up to tens of MbpsVariable (e.g., 9600 bps–1 Mbps)
SynchronizationSynchronous (clocked)Synchronous (clocked)Asynchronous (no clock)
Error HandlingACK/NACK handshakingNone (no built-in error checking)Parity bits (optional)
DistanceShort (<1m PCB)Short (<1m PCB)Longer (up to 10m)
Typical UseOn-board peripheral communication (sensors, EEPROMs)High-speed on-board communication (flash memory, displays)Serial communication between MCUs/PCs (e.g., USB-to-UART adapters)

Common I2C Peripherals and Applications

I2C is the dominant protocol for on-board communication in embedded systems, used with a wide range of peripherals:

  1. Sensors: Temperature (e.g., TMP102), humidity (e.g., SHT3x), pressure (e.g., BMP280), accelerometer (e.g., ADXL345), and gyroscope (e.g., L3GD20) sensors.
  2. Memory Devices: EEPROMs (e.g., 24LC256) and FRAMs for non-volatile data storage.
  3. Display Controllers: OLED/LCD display drivers (e.g., SSD1306 for OLEDs) and LED matrix controllers.
  4. Power Management: PMICs (Power Management Integrated Circuits) for voltage regulation and battery monitoring (e.g., MAX17043).
  5. Real-Time Clocks (RTCs): Timekeeping ICs (e.g., DS3231) for embedded systems requiring accurate time tracking.
  6. Audio Devices: DACs/ADCs (e.g., PCM5102) and audio codecs for consumer electronics (e.g., headphones, speakers).
  7. Industrial Control: PLCs (Programmable Logic Controllers) and I/O expanders (e.g., MCP23017) for adding digital input/output pins to MCUs.

Troubleshooting Common I2C Issues

  1. Bus LockupCaused by a slave device holding SDA/SCL low (e.g., due to a power failure mid-transmission). Fix: Reset the bus by cycling power or using a master-controlled reset circuit.
  2. Incorrect Pull-Up ResistorsToo large (e.g., 100kΩ) = slow rise times and data errors; too small (e.g., 1kΩ) = excessive power consumption. Fix: Use 2.2kΩ–4.7kΩ resistors for 3.3V systems, 4.7kΩ–10kΩ for 5V systems.
  3. Bus Capacitance ExceedanceCauses signal degradation at high speeds. Fix: Reduce the number of devices, shorten wire lengths, or use I2C bus extenders (e.g., TCA9548A multiplexers).
  4. Address ConflictsOccurs when two slaves have the same 7-bit address. Fix: Use slaves with programmable addresses (via hardware jumpers) or an I2C multiplexer to split the bus into separate channels.
  5. Noise InterferenceCauses incorrect ACK/NACK or data corruption. Fix: Route SDA/SCL lines away from high-speed digital lines/power supplies, use shielded cable for long runs, and add decoupling capacitors near device power pins.


了解 Ruigu Electronic 的更多信息

订阅后即可通过电子邮件收到最新文章。

Posted in

Leave a comment