UART, I²C and SPI

The three buses that connect most sensors, displays and radio chips to a microcontroller, and how to choose between them.

Foundation

How UART, I²C and SPI are wired UART joins exactly two devices with one wire each way and no shared clock. I²C shares two wires, SDA and SCL, held high by pull-up resistors, between many devices picked by address. SPI shares a clock and a data line each way, plus, usually, a separate chip-select line for each device. UART Exactly two devices One wire each way No shared clock Device A Device B TX RX RX TX Both ends set to the same baud rate, plus a shared ground I²C Two shared wires Many devices Each picked by an address, normally 7 bits Controller Supply pull-ups SDA (data) SCL (clock) Address A Address B SPI Clock + a data line each way Full-duplex Usually one chip-select line per device Controller Device 1 Device 2 Shared clock, data out, data in CS 1 CS 2
UART links two devices with a wire each way; I²C shares two wires among many addressed devices; SPI shares a clock and data lines and usually gives each device its own chip-select.

Key points

  1. A UART link is asynchronous: there is no shared clock, so both ends must be set to the same baud rate. It uses one wire each way (TX and RX) plus ground, and connects exactly two devices.12
  2. I²C uses two open-drain lines, SDA (data) and SCL (clock), held high by pull-up resistors. Many devices share the bus, each selected by an address, normally 7 bits.3
  3. The I²C specification defines Standard-mode (100 kbit/s), Fast-mode (400 kbit/s), Fast-mode Plus (1 Mbit/s) and High-speed mode (3.4 Mbit/s), plus a unidirectional Ultra Fast-mode (5 Mbit/s).3
  4. SPI is synchronous and full-duplex: a clock, a data line in each direction and, in the usual wiring, a separate chip-select line per device. Clock polarity and phase give four 'modes', and the controller must use the mode each device expects.4
  5. Old pin names (MOSI, MISO, SS) still appear on many datasheets. A 2020 Open Source Hardware Association resolution recommends SDO and SDI (named from each device's own side) and CS. For pins that switch with the role, it first used COPI/CIPO, now printed on many boards; its current text uses PICO/POCI.56
  6. MIPI I3C is a newer two-wire bus intended as a successor to I²C: it is faster, supports in-band interrupts and can share the bus with many legacy I²C devices.7

Common mistakes

  • Putting two I²C sensors with the same fixed address on one bus. Check the address options before choosing the second part.
  • Running I²C over long wires off the board. It was designed for short connections on one board.

Sources

  1. UART: A Hardware Communication Protocol · Analog Devices · Reference
  2. nRF Connect SDK Fundamentals, Lesson 4: UART protocol · Nordic Semiconductor (DevAcademy) · Vendor page
  3. UM10204: I2C-bus specification and user manual · NXP · Standard
  4. Introduction to SPI Interface · Analog Devices · Reference
  5. A Resolution to Redefine SPI Signal Names · Open Source Hardware Association · Standard
  6. OSHWA: A Resolution to Redefine SPI Signal Names · OSH Park blog · News
  7. MIPI I3C · MIPI Alliance · Standard