Protocols

SPI vs I2C: Complete Protocol Comparison Guide for Embedded Engineers

12 min read Protocols

SPI vs I2C: Understanding the Two Most Popular Serial Protocols

SPI (Serial Peripheral Interface) and I2C (Inter-Integrated Circuit) are the two most widely used serial communication protocols in embedded systems. Choosing between them is a fundamental decision that affects system performance, complexity, and cost. This comprehensive guide provides the technical depth needed to make informed design decisions.

Quick Comparison Summary

SPI Faster (up to 100+ MHz), more pins, point-to-point optimized
I2C Slower (up to 3.4 MHz), only 2 wires, true multi-master bus

SPI Protocol Deep Dive

Signal Description

SPI uses four primary signals for full-duplex communication:

  • SCLK (Serial Clock): Clock signal generated by the master
  • MOSI (Master Out Slave In): Data from master to slave
  • MISO (Master In Slave Out): Data from slave to master
  • SS/CS (Slave Select/Chip Select): Active-low signal to select slave device

SPI Clock Modes

SPI defines four clock modes based on Clock Polarity (CPOL) and Clock Phase (CPHA):

Mode CPOL CPHA Clock Idle Data Sampled Data Shifted
Mode 0 0 0 Low Rising Edge Falling Edge
Mode 1 0 1 Low Falling Edge Rising Edge
Mode 2 1 0 High Falling Edge Rising Edge
Mode 3 1 1 High Rising Edge Falling Edge

SPI Advantages

  • High Speed: Commonly 10-50 MHz, some devices support 100+ MHz
  • Full Duplex: Simultaneous bidirectional data transfer
  • Simple Protocol: No addressing overhead, no arbitration needed
  • Flexible Data Width: Not limited to 8-bit transfers
  • No Pull-ups Required: Push-pull outputs provide faster edges

SPI Disadvantages

  • Pin Count: Requires 3 + N pins (N = number of slaves)
  • No Acknowledgment: No built-in error detection
  • Short Distance: Limited by signal integrity at high speeds
  • Single Master: No standard multi-master support

I2C Protocol Deep Dive

Signal Description

I2C uses only two bidirectional signals:

  • SDA (Serial Data): Bidirectional data line
  • SCL (Serial Clock): Clock line (typically driven by master)

I2C Speed Modes

Mode Maximum Speed Typical Use Case
Standard Mode 100 kbps Basic sensors, EEPROMs
Fast Mode 400 kbps Most modern I2C devices
Fast Mode Plus (Fm+) 1 Mbps High-performance sensors
High Speed Mode 3.4 Mbps Specialized applications

I2C Addressing

I2C supports two addressing modes:

  • 7-bit Addressing: Up to 128 devices (112 usable, 16 reserved)
  • 10-bit Addressing: Up to 1024 devices

I2C Protocol Features

  • START Condition: SDA falls while SCL is high
  • STOP Condition: SDA rises while SCL is high
  • ACK/NACK: Receiver pulls SDA low (ACK) or leaves high (NACK)
  • Clock Stretching: Slave can hold SCL low to slow communication
  • Arbitration: Multiple masters can coexist with collision detection

I2C Advantages

  • Minimal Wiring: Only 2 wires for any number of devices
  • Addressing: Each device has unique address, no chip select needed
  • Multi-Master: Built-in arbitration for multiple masters
  • Acknowledgment: Built-in ACK/NACK for error detection
  • Hot-Plugging: Devices can be added/removed dynamically

I2C Disadvantages

  • Speed Limited: Maximum 3.4 Mbps (typically 400 kbps used)
  • Half Duplex: Cannot send and receive simultaneously
  • Pull-up Resistors: Required, affect rise time and power
  • Addressing Conflicts: Fixed addresses can cause conflicts
  • Bus Capacitance: Limited to 400 pF total bus capacitance

Detailed Technical Comparison

Parameter SPI I2C
Maximum Speed 100+ MHz 3.4 MHz
Minimum Wires 4 (3 + 1 per slave) 2
Duplex Full Duplex Half Duplex
Addressing Chip Select lines 7-bit or 10-bit address
Multi-Master Not standard Built-in support
Acknowledgment None ACK/NACK after each byte
Clock Master only Master (with stretching)
External Components None required Pull-up resistors
Power Consumption Higher (push-pull) Lower (open-drain)
Protocol Overhead None Start, Address, ACK, Stop

When to Use SPI vs I2C

Choose SPI When:

  • Speed is Critical: Applications requiring >1 Mbps throughput
  • Streaming Data: ADCs, DACs, displays, flash memory
  • Full Duplex Needed: Simultaneous read/write operations
  • Few Devices: Small number of peripherals (1-4)
  • No Multi-Master: Single controller systems
SPI Device Examples: Flash memory (W25Q), SD cards, displays (ILI9341), high-speed ADCs (ADS8xxx), radio modules (nRF24L01)

Choose I2C When:

  • Pin Count Matters: Limited GPIO availability
  • Many Devices: Connecting numerous sensors/peripherals
  • Multi-Master Required: Multiple controllers on same bus
  • Hot-Plugging Needed: Dynamic device connection
  • Low Speed Acceptable: Configuration, sensor reading
I2C Device Examples: Temperature sensors (TMP102), accelerometers (MPU6050), EEPROMs (24Cxx), RTCs (DS3231), GPIO expanders (PCF8574)

Implementation Best Practices

SPI Implementation Tips

  1. Match Clock Modes: Verify CPOL/CPHA settings match device requirements
  2. CS Timing: Ensure proper setup/hold times for chip select
  3. Signal Integrity: Keep traces short at high frequencies, use ground planes
  4. MSB/LSB First: Confirm bit order matches device expectations
  5. FIFO Depth: Use FIFOs to reduce CPU overhead in IP cores

I2C Implementation Tips

  1. Pull-up Selection: Calculate based on bus capacitance and speed mode
  2. Address Verification: Check for conflicts before system integration
  3. Clock Stretching Timeout: Implement timeout to prevent bus lockup
  4. Bus Recovery: Implement stuck bus recovery (9 clock pulses)
  5. Glitch Filtering: Use filtering on SDA/SCL for noise immunity

I2C Pull-up Resistor Calculation

Minimum: Rmin = (VCC - VOL) / IOL

Maximum: Rmax = tr / (0.8473 x Cb)

Where: VOL = 0.4V, IOL = 3mA (standard mode), tr = rise time, Cb = bus capacitance

Conclusion

Both SPI and I2C have their place in embedded system design. SPI excels in high-speed, streaming applications where throughput is paramount, while I2C shines in multi-device, pin-constrained systems requiring flexibility and simplicity.

Many modern designs use both protocols: SPI for high-bandwidth peripherals like displays and flash memory, and I2C for low-speed sensors and configuration interfaces. Understanding the strengths and limitations of each protocol enables optimal system architecture decisions.

Vcores offers silicon-proven SPI and I2C IP cores with configurable features, comprehensive verification, and easy integration for your FPGA and ASIC designs.

Tags: SPI protocol I2C protocol serial communication embedded systems FPGA microcontroller

Need IP Cores for Your Design?

Vcores offers silicon-proven IP cores for ASIC and FPGA designs. Get high-quality, verified IP with comprehensive documentation and support.

Explore Products Contact Us