GlossarySPI vs I2C
SPI vs I2C
SPI and I2C are two widely used serial buses that connect chips on the same board, such as sensors and memories, to a microcontroller. SPI uses separate data lines and a select line per device for fast, full-duplex transfers. I2C uses two shared lines and device addresses, trading speed for fewer wires.
How it works
SPI, the serial peripheral interface, has a clock line, a data line from the controller to the device, a data line back, and a chip select line for each device. The controller pulls one chip select low, then clocks data out and in at the same time. The protocol has no addressing or acknowledgment and no single formal standard: clock polarity, clock phase, word length and command sets come from each device's datasheet.
I2C, the inter-integrated circuit bus, uses a serial data line (SDA) and a serial clock line (SCL), both open-drain with pull-up resistors. Each device has an address. The controller sends a start condition, the address and a read or write bit, and the addressed device acknowledges each byte. The I2C-bus specification defines Standard-mode at up to 100 kbit/s, Fast-mode at up to 400 kbit/s and Fast-mode Plus at up to 1 Mbit/s. MIPI I3C is a newer bus that keeps compatibility with I2C devices while adding speed.
SPI vs I2C side by side
| SPI | I2C | |
|---|---|---|
| Wires | Clock, two data lines, one select per device | Two shared lines |
| Speed | Faster, set by each device's datasheet | Up to 100 kbit/s, 400 kbit/s or 1 Mbit/s in common modes |
| Duplex | Full duplex | Half duplex |
| Addressing | A chip select line per device | A 7-bit or 10-bit address |
| Acknowledgment | None in the protocol | Every byte |
| Typical parts | IMUs, flash, converters, displays | Slow sensors, EEPROMs, power monitors, port expanders |
Why it matters
The bus choice sets pin count, routing and data rate. A high-rate IMU on I2C limits how fast a flight controller reads it, while the same part on SPI delivers samples faster and with less overhead. I2C saves pins, but its lines are shared, so one stuck device can hold the bus low for every other device, and the pull-ups and bus capacitance limit speed and length.
How to get it right
- Use SPI for high-rate sensors and memory, and I2C for configuration and slow peripherals.
- Size I2C pull-ups for the bus capacitance and speed, following the specification.
- Check for I2C address conflicts on the schematic before layout.
- Keep SPI clock traces short, and add series resistors where edges ring.
- Give each SPI device its own chip select, and hold the selects inactive at reset.
- Keep both buses on the board or on short cables, and use CAN between modules.
- Bring bus lines out to test points for debug and functional test.
SPI and I2C in robotics and drone hardware
Flight controllers and robot sensor boards usually put IMUs on SPI for speed, and barometers, magnetometers and power monitors on I2C. PX4's guide to I2C peripherals recommends I2C for low-bandwidth parts such as rangefinders and magnetometers, and a CAN bus such as DroneCAN where higher rates or longer cable runs are needed. An external compass on a long I2C cable picks up noise from motor wiring, which shorter cables, twisted pairs and correctly sized pull-ups address.