Serial Peripheral Interface Bus (SPI)

SPI (Serial Peripheral Interface Bus) is a high-speed, synchronous serial communication bus widely used in embedded systems. It supports full-duplex (4-wire mode), fast data transfer rates, and a simple master–slave structure..

Used in:

  • Flash memory (W25Q series)
  • ADC/DAC
  • IMU sensors
  • LCD/OLED/TFT displays
  • Real-time clocks
  • FPGA communication

Interface and Features

SPI features include:

  • SPI signals include:
    • SCLK: Serial Clock (output from master)
    • MOSI: Master Output Slave Input (data output from master)
    • MISO: Master Input Slave Output (data output from slave)
    • /SS: Slave Select (often active low, output from master)
    • SDAT: Serial Data I/O (bidirectional I/O, combined MOSI and MISO signals together)
  • Data length: 3- to 16-bit data width
  • Bit rate: supports up to 18 Mbps
  • SPI serial bus can be configured as 4-wire (default) and 3-wire mode

SPI Clock Modes (CPOL + CPHA)

SPI has no pre-defined protocol, so the master and slave must agree on the data frame for the exchange. The data frame is described by clock polarity (CPOL) and clock phase (CPHA). The CPOL parameter defines whether the clock is idle when high or low. The CPHA parameter is used to shift the sampling phase. If CPHA = 0, the data will be sampled on the leading (first) clock edge. If CPHA = 1, the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling. The 4 modes combine polarity and phase according to the following table:

Table: SPI Clock Phase (CPHA) and Clock Polarity (CPOL) Operation

Mode Clock Polarity
(CPOL)
Clock Phase
(CPHA)
SCLK Transmit Edge SCLK Receive Edge SCLK Idle State
0 0 0 Falling Rising Low
1 0 1 Rising Falling Low
2 1 0 Rising Falling High
3 1 1 Falling Rising High

CPOL: used for clock idle state

  • 0 — Clock idle low level
  • 1 — Clock idle high level

CPHA: used to shift the sampling phase

  • 0 — Data Sampled at the leading edge (no delay)
  • 1 — Data Sampled at the trailing edge (delay)

SPI Bus Connection Modes

SPI has two common wiring modes: 4-wire (standard full-duplex) and 3-wire (half-duplex). Both follow the SPI master-slave protocol, but they differ in wiring, performance, and use cases.

4-Wire SPI (Standard Full-Duplex Mode)

4-wire serial bus mode: SCLK, MOSI, MISO, AND SS signals

Signal Direction Description
SCLK Master → Slave Serial Clock
MOSI Master → Slave TX From Master
MISO Slave → Master RX From Slave
CS/SS Master → Slave Chip Select/Slave Select (active low)

 

4-wire bus mode is the SPI standard connection mode. It supports full-duplex data transactions, which means SPI allows transmitting and receiving data simultaneously on two data lines (MOSI and MISO),

SPI Connections for Multiple Slaves

SPI devices communicate in full-duplex mode using a master-slave architecture with a signal master. There are two ways to connect multiple slaves with a master:

Summary Table — When to Choose Which?

Requirement Best CHoice
Highest speed 4-Wire SPI
Full-duplex needed 4-Wire SPI
MCU has many GPIOs 4-Wire SPI
Low-pin-count design 3-Wire SPI
Display controllers that use SDI/SDO 3-Wire SPI
Daisy-chain LED drivers 4-Wire SPI
Cost-sensitive design 3-Wire SPI
High data throughput 4-Wire SPI

 

Conclusion

4-Wire SPI is faster, simpler, and offers full duplex, making it ideal for high-performance applications.

3-Wire SPI reduces pin count and PCB complexity but introduces half-duplex constraints and requires careful control of the shared SDIO line.

Both modes follow the SPI protocol but are optimized for different hardware design priorities:

        • 4-Wire = Performance & Simplicity
        • 3-Wire = Pin Saving & Compact Design

To write code for a new SPI device, you need to note a few things:

  • What is the maximum SPI clock speed the device can use?
  • Is data first shifted in the Most Significant bit (MSb) or the Least Significant bit (LSb)?
  • Is the data clock idle when high or low? Are samples on the rising or falling edge of clock pulses?
  • Is the connection in 4-wire or 3-wire mode?

Reference:

© 2025 Air Supply Information Center (Air Supply BBS)