Principles, Differences, and Connections of the Three Major Embedded Protocols: UART, SPI, and I²C

Principles, Differences, and Connections of the Three Major Embedded Protocols: UART, SPI, and I²C

1. UART (Universal Asynchronous Receiver/Transmitter)

  • The host and slave must connect at least three wires: RX, TX, and GND. TX is used for sending data, while RX is for receiving data (the transmission and reception are not on the same line, hence it is full-duplex).

  • Principles, Differences, and Connections of the Three Major Embedded Protocols: UART, SPI, and I²C
  • Basic Characteristics:

    • Asynchronous Communication: No shared clock signal, relies on predefined baud rate for synchronization.

    • Full-Duplex: Supports simultaneous sending (TX) and receiving (RX).

    • Point-to-Point: Only supports communication between two devices.

    • Data Frame Format: Start bit + Data bits (5-9 bits) + Optional parity bit + Stop bit.

    • Hardware Requirements: Only requires three wires (TX, RX, and GND, usually simplified to TX and RX).

  • Advantages:

  • Simple hardware, low cost. Supports long-distance communication (with RS-232/RS-485 level conversion).

  • Disadvantages:

    • Baud rate must be strictly consistent, otherwise data errors occur. No support for multiple devices, poor scalability. Relatively low speed (usually ≤ 115200 bps).

  • Typical Applications:

    • Debugging serial ports (e.g., communication between Arduino and PC). Simple peripherals like GPS modules, Bluetooth modules.

2. SPI (Serial Peripheral Interface)

  • SPI is a serial synchronous communication protocol consisting of one master device and one or more slave devices. The master device initiates synchronous communication with the slave device to complete data exchange. The SPI interface consists of four signals: SDI (Serial Data Input), SDO (Serial Data Output), SCK (Clock Signal), and CS (Chip Select), which determines the specific slave device communicating with the master. The chip select signal is active low. If there is no CS signal, only one slave device can exist, and the master initiates communication by generating a shift clock. During communication, data is output from SDO and input to SDI, with data being output on the rising or falling edge of the clock and read on the subsequent edge, completing 8/16-bit data transmission after 8/16 clock changes.

  • Principles, Differences, and Connections of the Three Major Embedded Protocols: UART, SPI, and I²C

  • Basic Characteristics:

    • Synchronous Communication: The master device controls data transmission via the clock line (SCLK).

    • Full-Duplex: Master and slave devices can send and receive data simultaneously.

    • Master-Slave Architecture: Supports one master and multiple slaves, each requiring an independent chip select line (SS/CS).

    • Data Frame Format: No fixed standard, typically 8-bit or 16-bit data blocks.

    • Hardware Requirements: SCLK, MOSI (Master Out Slave In), MISO (Master In Slave Out), SS (one for each slave device).

  • Advantages:

    • High transmission rate (up to over 100 Mbps). Simple protocol with high flexibility (no addressing mechanism, direct control of chip select). Full-duplex communication, high efficiency.

  • Disadvantages:

    • Complex hardware wiring (each additional slave device requires an extra chip select line). No error detection mechanism, relies on software handling. Only supports short-distance communication (usually ≤ 1 meter).

  • Typical Applications:

    • High-speed peripherals (e.g., SD cards, TFT displays).

    • Sensors (e.g., accelerometers, gyroscopes).

3. I²C (Inter-Integrated Circuit)

  • The I²C bus is a bidirectional, two-wire (SCL, SDA), serial, multi-master interface standard with a bus arbitration mechanism, making it very suitable for short-distance, infrequent data communication between devices. In its protocol system, data transmission includes the address of the target device, enabling device networking. If simulating the I²C bus with general I/O ports and achieving bidirectional transmission, one input/output port (SDA) and one output port (SCL) are required.

  • Principles, Differences, and Connections of the Three Major Embedded Protocols: UART, SPI, and I²C

  • Basic Characteristics:

    • Synchronous Communication: The master device synchronizes the data line (SDA) via the clock line (SCL).

    • Half-Duplex: Only supports unidirectional data transmission at any given time.

    • Multi-Master Multi-Slave: Supports multiple master and slave devices sharing the bus.

    • Addressing Mechanism: Each slave device has a unique 7-bit or 10-bit address.

    • Hardware Requirements: Only requires two wires (SCL and SDA, plus GND).

  • Advantages:

    • Simple hardware, supports multiple devices (bus topology).

    • Built-in conflict detection and arbitration mechanism to avoid bus conflicts.

    • Moderate speed (standard mode 100 kbps, fast mode 400 kbps, high-speed mode 3.4 Mbps).

  • Disadvantages:

    • Half-duplex, less efficient than SPI. Bus capacitance limits the number of devices and communication distance.

  • Software implementation is relatively complex (needs to handle ACK/NACK, bus arbitration, etc.).

  • Typical Applications:

    • Low-speed sensors (e.g., temperature and humidity sensors).

    • Storage devices like EEPROM, RTC (real-time clock).

Differences and Connections Among the Three

Characteristic UART SPI I²C
Sync/Async Asynchronous Synchronous Synchronous
Communication Method Full-Duplex Full-Duplex Half-Duplex
Number of Devices Only 2 devices One master, multiple slaves Multi-master, multi-slave
Number of Wires 2 wires (TX/RX) 3+N wires (SCLK/MOSI/MISO + N chip selects) 2 wires (SCL/SDA)
Speed Low (≤ 115200 bps) High (up to 100 Mbps) Medium (≤ 3.4 Mbps)
Addressing Method No addressing mechanism Select slave via chip select 7-bit/10-bit device address
Error Detection Parity (optional) None ACK/NACK mechanism
Typical Applications Simple point-to-point communication High-speed peripherals Multi-device low-speed systems

Selection Recommendations

  1. UART: Suitable for simple, low-speed point-to-point communication (e.g., debugging interfaces).

  2. SPI: Required for high-speed transmission or full-duplex scenarios (e.g., storage devices, displays).

  3. I²C: Systems with many devices and low-speed requirements (e.g., sensor networks).

Summary

  • UART is known for its simplicity and low cost but has poor scalability.

  • SPI excels in speed and flexibility but has complex hardware.

  • I²C strikes a balance between the number of devices and hardware complexity but is limited in speed.

Leave a Comment