SPI is generally faster and better for high-throughput data streaming, while I²C is better for connecting many simple devices using fewer wires.
The choice between them depends on your project’s specific needs for speed, number of connected devices, and available pins on your microcontroller.
At a Glance: I²C vs. SPI
| Feature | I²C (Inter-Integrated Circuit) | SPI (Serial Peripheral Interface) |
|---|---|---|
| Wires Required | 2 wires (SDA, SCL) + pull-up resistors + power/ground | 4 wires (MOSI/COPI, MISO/CIPO, SCLK, CS) + power/ground (3 if unidirectional) |
| Max Speed | Slower (100 kbps Standard, 400 kbps Fast, 1 Mbps Fast-mode Plus, 3.4 Mbps High-Speed; 5 Mbps Ultra-Fast is unidirectional push-pull without ACK) | Much faster (typically 1–50 Mbps; 100 Mbps+ with Quad/Octal SPI) |
| Data Flow | Half-Duplex (data sends or receives) | Full-Duplex (data sends and receives simultaneously) |
| Device Addressing | Built-in 7-bit (112 usable addresses; 16 reserved) or 10-bit addressing | No addressing; uses a dedicated Chip Select (CS) line per device (or daisy-chaining) |
| Hardware Complexity | More complex protocol, but simpler wiring (requires pull-ups) | Simpler protocol, but more complex wiring for multiple devices |
| Key Advantage | Uses very few pins to connect many devices | Raw speed, push-pull signalling, and simple data transfer |
I²C (Inter-Integrated Circuit)
I²C uses a shared open-drain bus, meaning multiple devices connect to the same two pins on your microcontroller. (Note: NXP’s I²C spec Rev 7.0 uses Controller/Target terminology in place of Master/Slave.)
Pros
- Fewer Wires: Only needs two signal wires (
SDAfor data andSCLfor clock) plus pull-up resistors, regardless of how many devices are on the bus. This is a huge advantage when you are low on available pins. - Built-in Addressing: Each device has an address (7-bit gives 112 usable addresses with 16 reserved; 10-bit addressing is also supported). The controller selects a target by sending its address first.
- Acknowledgement System: The protocol includes acknowledgement (
ACK) and negative-acknowledgement (NACK) bits confirming a target responded to its address or received a byte. (Note:ACKdoes not verify data integrity — I²C has no built-in CRC/checksum, so a corrupted byte is still ACKed.) - Multi-Controller Support: The I²C standard allows multiple controllers on the same bus via arbitration, though this is complex and rarely used in simple projects.
Cons
- Slower Speed: The primary bottleneck is electrical: I²C uses open-drain outputs with passive pull-up resistors (typically 2.2–10 kΩ), so rise times are RC-limited by bus capacitance (max 400 pF in Standard/Fast mode). Protocol overhead (start/stop, addressing, ACK/NACK) adds further overhead.
- Requires Pull-Up Resistors & Address Management: External pull-ups on
SDAandSCLare mandatory, and identical sensors often share a fixed address (requiring address-select pins or an I²C multiplexer). - Half-Duplex: Data can only travel in one direction at a time on the single data line.
- More Complex Protocol: The controller must manage addresses, clock stretching, acknowledgements, and bus recovery states, making driver logic more complex.
SPI (Serial Peripheral Interface)
SPI uses a controller-peripheral (master-slave) push-pull architecture where one controller manages communication with one or more peripherals. (Modern terminology increasingly uses COPI/CIPO or SDO/SDI alongside MOSI/MISO.)
Pros
- High Speed: Active push-pull drivers and minimal protocol overhead make SPI much faster than I²C — ideal for displays, SD cards, flash memory, and fast ADCs.
- Full-Duplex: With separate lines for sending (
MOSI/COPI) and receiving (MISO/CIPO), data can be sent and received simultaneously. - Simple Protocol: The controller pulls a peripheral’s Chip Select (
CS) line low and clocks data directly. There is no addressing or acknowledgement overhead to manage.
Cons
- More Wires: Requires four signal wires for a full-duplex device (three if unidirectional, e.g. write-only displays).
- Complex Wiring for Multiple Devices: With independent chip selects, each additional peripheral needs its own
CSline (3 + Npins total — connecting five SPI devices requires eight pins:MOSI,MISO,SCLK, and fiveCSlines), unless the devices support daisy-chaining with a sharedCS. - No Acknowledgement: There is no built-in confirmation that a peripheral is present or received the data.
- No Formal Standard & Mode Matching: SPI has no single governing specification, does not natively support multiple controllers, and both ends must match clock polarity/phase (SPI Modes 0–3, controlled by
CPOL/CPHA).