Serial Peripheral Interface (SPI)

Overview

The Serial Peripheral Interface (SPI) is a synchronous, full-duplex serial communication protocol commonly used in embedded systems to connect a master device (often a microcontroller) with one or more slave devices (peripherals). It is widely valued for its speed, simplicity, and flexibility, enabling high-throughput data transfers with relatively low overhead.

Core Characteristics

  • Synchronous - Data is transmitted in sync with a clock signal (SCLK) generated by the master.

  • Full-duplex - Data flows in both directions simultaneously.

  • Master-driven - The master controls the clock, initiates communication, and selects the slave device(s).

  • Point-to-point or multi-slave - Works with a single slave or multiple slaves, each with a dedicated chip select line.

Physical Interface

The most common configuration uses four signals:

Signal Direction (Master POV) Function

SCLK (Serial Clock)

Output

Clock signal that synchronizes data exchange.

CS / SS (Chip Select / Slave Select)

Output

Active-low line used to select a specific slave.

MOSI (Master Out, Slave In)

Output

Data from master to slave.

MISO (Master In, Slave Out)

Input

Data from slave to master.

How it works:

  1. The master pulls CS low to select the target slave.

  2. On each clock pulse, a bit is shifted out from MOSI and simultaneously a bit is shifted in from MISO.

  3. When done, the master sets CS high to end the transaction.

Communication Process

  1. Initialization - Master configures clock speed, CPOL, CPHA, and selects the desired slave.

  2. Selection - CS line goes low to activate the slave.

  3. Data Transfer -

    1. Master shifts out data on MOSI.

    2. Slave shifts out data on MISO.

    3. Both sides sample incoming data on the configured clock edge.

  4. Completion - CS line returns high, ending communication.

Performance and Limitations

  • Speed - Can reach tens of MHz, much faster than I²C in most cases.

  • Distance - Best for short PCB or cable runs (typically under ~1 m).

  • No Addressing - Requires a separate CS line for each slave, limiting scalability.

  • No Acknowledgment - Unlike I²C, there’s no ACK/NACK; error detection must be implemented at a higher layer if needed.

Common Applications

SPI is found in many devices, including:

  • Memory - Flash chips, EEPROMs

  • Sensors - Accelerometers, gyroscopes, temperature sensors

  • Display Modules - LCD, OLED

  • Data Converters - ADCs, DACs

  • Communication Modules - RF transceivers, Wi-Fi chips