UART · 115200 baud · 8.68 µs per bitTX0start1b00b10b20b30b40b51b60b71stop086.8 µsI2C · 100 kHz · 90 µs per byte + ACKSCLSDASTART1a61a51a40a31a21a10a00W0ACKSTOP090 µsSPI · 10 MHz · 0.8 µs per byteCSSCLKMOSIMISO11010000000101000000000001.6 µsbyte 1byte 2Time to move one byteUART 115200 baud86.8 µsI2C 100 kHz90 µsI2C 400 kHz22.5 µsSPI 10 MHz0.8 µsTXRXSDASCLSCLKMOSIMISOCSRXTXSCLKMOSIMISOCS3.3V3.3VUARTrx--MCUrx--0x3C0x76SPIrx--00000000000000000000
Lit wire with moving dashes: the bus is in useTokens: one bit each; a glowing token is a 1. Purple discs are clock ticksChips: the microcontroller on the left, sensors on the rightTiming screen: each wire's voltage over time; the playhead moves with the bitsA serial bus sends one bit at a time on each data wire; a parallel bus sends several bits at once on several wires. Fewer wires means fewer pins and simpler boards. UART frames here use 8 data bits, no parity bit and 1 stop bit (written 8N1). Data bits go least significant bit first (Analog Devices, UART: A Hardware Communication Protocol). I2C timings and rules are from NXP's I2C-bus specification (UM10204): Standard-mode runs up to 100 kbit/s and Fast-mode up to 400 kbit/s. Each byte is followed by an ACK bit, so it takes nine clock pulses. SPI has no single official standard; this figure uses the common mode 0 (clock idle low, data read on the rising edge), most significant bit first (Analog Devices, Introduction to SPI Interface).

Why serial

  1. A microcontroller is a small computer on one chip, and it often talks to sensor chips. Eight wires for a byte's eight bits would use many pins. A serial bus sends the bits one after another over a few wires.

UART

I2C

SPI

Choosing a bus

The bits, one by one

;; step 1/10 · why-serial
;; about: Microcontroller, UART sensor, Sensor 0x76, SPI sensor
parallel: 8 wires, 1 byte at once
serial:   1 data wire, 8 bits in a row

Three common serial buses:
  UART  2 wires  TX, RX
  I2C   2 wires  SDA, SCL (shared)
  SPI   4 wires  SCLK, MOSI, MISO, CS

bus: shared wires plus the rules for
using them

The figure plays in slow motion. Real bits do not travel as little packets: the voltage on the whole wire changes almost at once, and the receiver reads it at the right moment. The sensor is modelled on the Bosch BME280, which speaks both I2C and SPI: its I2C address is 0x76 or 0x77, its ID register 0xD0 reads 0x60, and its SPI clock may run up to 10 MHz.