Communication protocols (I2C, SPI, UART)
Three ways chips pass bytes to each other over a few wires. Watch the same byte, 0x4B, travel bit by bit over UART, SPI and I2C, and see what each one costs in wires.
In 30 seconds
Chips on a circuit board talk by sending bits one after another along a wire. The hard part is timing: the receiver must know when each bit starts.
UART uses no clock wire; both sides agree on a speed and each byte is framed by a start and a stop bit. SPI adds a clock wire and a select wire per chip, and is the fastest.
I2C shares just two wires among many chips and begins each message with the address of the chip it wants.
Communication protocols (I2C, SPI, UART), step by step
Shown: UART with 8 data bits, no parity and one stop bit; SPI in its most common mode (mode 0); I2C with 7-bit addresses. Other settings exist. Addresses 0x48, 0x3C and 0x68 are typical examples.
- Step 1: UART: two wires, no clock. Chips send data serially: one bit after another, as a high or low voltage on a wire. The oldest scheme is UART. Each side has a transmit pin (TX) wired to the other side’s receive pin (RX), so both can talk at once. There is no clock wire. Instead both sides are set in advance to the same speed, here 9600 bits per second.
- Step 2: UART: one byte on the wire. The idle line is high. To send the byte 0x4B (0100 1011) it drops low for one bit, the start bit, and that falling edge starts the receiver’s timer. Eight data bits follow, least significant first, then a high stop bit. The receiver reads in the middle of each bit. At 9600 bits per second a bit lasts about 104 microseconds.
- Step 3: SPI: add a clock wire. SPI stops guessing the timing: the controller sends a clock on its own wire, SCK, and every tick marks one bit. Data goes out on MOSI and comes back on MISO at the same time. A fourth wire, chip select (CS), tells one particular chip to pay attention. More chips share the first three wires but each needs its own CS.
- Step 4: SPI: one byte on the wire. The controller pulls CS low, then puts each bit on MOSI and pulses the clock. The chip reads MOSI at the instant the clock rises. Eight ticks carry 0x4B, most significant bit first, and CS goes high again. No start or stop bits are needed, and because the clock travels with the data it can run fast: millions of bits per second.
- Step 5: I2C: two shared wires. I2C needs just two wires however many chips there are: SDA for data and SCL for the clock. Every chip hangs on the same pair and has its own 7-bit address. Resistors pull both wires high; a chip signals by pulling a wire low. The controller starts every message with the address of the chip it wants, and only that chip responds.
- Step 6: I2C: one byte on the wire. Writing 0x4B to the sensor: a START, when SDA falls while SCL is high, wakes every chip. Seven address bits follow (1001000 is 0x48), then a 0 meaning write. On the ninth clock the sensor pulls SDA low: an acknowledge (ACK), “that is me”. Then come the eight data bits, another ACK, and a STOP, when SDA rises while SCL is high.
- Step 7: Which one to use. Each protocol trades wires against speed and reach. UART links exactly two devices and needs no clock wire, which suits modules and debug consoles. SPI is the fastest but costs an extra wire per chip, so it serves displays and memory. I2C is slower, yet two wires can serve many chips: ideal for a board full of small sensors.
Try it yourself
Learn this first
Learn next
Spotted a mistake on this page?