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.
| Bus | Wires | Speed | Best for |
|---|---|---|---|
| I2C | 2 | 100 kHz, 400 kHz, 1 MHz, 3.4 MHz | Several low-speed devices on one board |
| SPI | 3 plus one per device | Tens of MHz | Fast peripherals: flash, displays, ADCs |
| UART | 2 | Commonly 9,600 - 115,200 baud and above | Point-to-point links and debug |
| CAN | 2, differential | Up to 1 Mbps; CAN FD faster in the data phase | Noisy environments and long cables |
| USB 2.0 | 2, differential, plus power | 12 Mbps or 480 Mbps | Connection to a computer or phone |
| kHz | |
|---|---|
| Standard | 100 |
| Fast | 400 |
| Fast-mode Plus | 1000 |
| High-speed | 3400 |
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.