I2C, SPI, UART, CAN and USB: Picking the Right Bus

A microcontroller talks to the rest of the board through a handful of serial interfaces, and they are not interchangeable. I2C connects many slow devices with two wires. SPI is fast and simple but needs a wire per device. UART links two points. CAN survives noisy, long cable runs. USB brings standard connectivity to a host. This article compares them with the figures that decide the choice.

At a glance

400 kHz
I2C Fast-mode clock rate, the most common setting for sensors.
2 wires
I2C needs only clock and data, shared by every device on the bus.
1 Mbps
Maximum bit rate of classic CAN, at bus lengths up to about 40 m.
480 Mbps
USB 2.0 High-Speed signalling rate; Full-Speed is 12 Mbps.

The problem

Problems appear when a bus is used outside what it was designed for. I2C run over a long cable picks up noise and its open-drain edges slow down with capacitance. SPI with many devices consumes a chip-select pin each. UART has no clock, so both ends must agree on the baud rate closely.

On-board buses also offer no protection against the outside world. Anything that leaves the enclosure needs a bus built for it, with differential signalling and proper protection.

On-board buses stay on the board. Once a signal leaves the enclosure, use an interface designed for cables.

A way to decide

For several low-speed sensors on the same board, use I2C and check that the total bus capacitance stays within the 400 pF limit. For displays, flash memory and fast converters, use SPI.

For a link between two processors or to a debug console, UART is simplest. For anything on a cable in an electrically noisy setting, use CAN or RS-485. For a connection to a computer or phone, use USB.

What good looks like

List each device with the data rate it needs and its distance from the controller.

Assign on-board devices to I2C or SPI by speed, and off-board links to CAN, RS-485 or USB.

Check the electrical limits: pull-up values and capacitance on I2C, trace length on fast SPI, termination on CAN.

Serial buses compared
BusWiresSpeedBest for
I2C2100 kHz, 400 kHz, 1 MHz, 3.4 MHzSeveral low-speed devices on one board
SPI3 plus one per deviceTens of MHzFast peripherals: flash, displays, ADCs
UART2Commonly 9,600 - 115,200 baud and abovePoint-to-point links and debug
CAN2, differentialUp to 1 Mbps; CAN FD faster in the data phaseNoisy environments and long cables
USB 2.02, differential, plus power12 Mbps or 480 MbpsConnection to a computer or phone
Figures from the respective specifications. Practical speed depends on layout and cable length.
I2C speed modes
kHz
Standard100
Fast400
Fast-mode Plus1000
High-speed3400
Maximum clock rates defined by the I2C specification.

What it changes

Reliable Links

Each bus operates inside the conditions it was designed for.

Pin Efficiency

Shared buses free microcontroller pins for other functions.

Noise Immunity

Differential buses are used wherever cables and interference are involved.

Simpler Firmware

Standard buses come with proven drivers and well-understood failure modes.

Where to go next

Plan I2C addresses early. Two devices with the same fixed address cannot share a bus without a multiplexer.

Bring debug access out on every board: at minimum a UART header and the programming interface.

Problems this prevents

  • I2C stretched over a long cable
  • I2C address clashes found at bring-up
  • SPI running out of chip-select pins
  • An unprotected logic signal leaving the enclosure

Discuss your project

Email support@aavico.com or use Get in Touch when the website finishes loading.