Espurna
EN
CommunicationBasicUARTI2CSPICANbusprotocol

How chips talk (UART, I2C, SPI, CAN)

In 30 secondsA bus is a set of shared wires. Each protocol has its own way of deciding who talks, to whom and when: UART point to point, I2C by address, SPI with a select wire and CAN by message ID.

Also available in: Català · Castellano

The idea

A bus is a set of wires shared by several devices. Three problems need solving: who talks, to whom and when.

Protocol Wires How it picks the recipient Typical speed
UART 2 (TX, RX) Not needed: point to point 9600 to 1 Mbaud
I2C 2 (SDA, SCL) 7-bit address 100 or 400 kHz
SPI 4 + one CS per device Pulls the chosen device’s CS line low Several MHz
CAN 2 differential Message ID; the lowest wins Up to 1 Mbit/s

Typical values; they depend on the chip.

UART

Start bit (line low), 8 data bits with the least significant first, and a stop bit. The baud rate sets the speed. It’s the basis of USB-serial adapters, GPS modules and the Feetech servo bus.

I2C

The address is sent first; only the matching device answers with an ACK. If nobody has that address, you get a NACK. Used in IMUs, displays and small sensors.

SPI

The controller pulls low the CS (chip select) line of the device it wants. Data goes out and comes in at the same time. Fast, but with more wires.

CAN

Nobody has an address: each message carries an ID. If two talk at once, the lower ID wins and nothing is lost (arbitration). Used in cars and robot joints.

In the demo

One tab per protocol. In I2C, try an address nobody has to see the NACK.

Interactive demo

Related concepts