← Writing

SPI (Serial Peripheral Interface)

2025-06-30 embedded · basic · sp


A technical introduction to the SPI - low-speed four-wire master-slave full-duplex serial protocol.
SPI is widely used as a faster alternative to UART/I2C for transferring data between an intelligent controller and a less intelligent peripheral device.


    SPI

SPI - Serial Peripheral Interface A protocol in which there is one leader (master or controller) and one or more slaves (or peripheral device)
Usually operates in full-duplex (both nodes transmit data simultaneously)
Message exchange occurs in frames. SPI has no agreement on frame formats, number of transmitted bits and voltage levels

    SPI Design

  1. switch the SC line low(0), indicating that information will be transferred to this slave
  2. starts the SCLK signal
  3. transfer occurs on (MOSI / MISO)
  4. switch CS back to high(1)

SCLK

The clock signal in SPI by default idle can be in a low(0) or high(1) state, and data can be read on the rising or falling edge of the signal.

MOSI

Used to send data from a master to a slave After CS is pulled low(0) and SCLK is enabled, MOSI is used to transfer data from the master to the slave as an 8-bit bytes, where the first bit can be the least significant bit (LSB, MSB).
Multiple bytes can be transferred while CS is low(0).

MISO

Used to send data from a slave to a master

    SPI Adjustment

Clock Polarity

CPOL - the clock signal generated by the master can be:

  1. low(0) at idle, active at high(1) level (CPOL = 0. “non-inverted”) (Leading (first edge)- rising)
  2. high(1) at idle, active at low(0) level (CPOL = 1. “inverted”) (Leading (first edge)- falling) CPOL indicates which of these options is used

For both types of clock pulse polarity, you can focus on

  1. leading edge of the clock pulse (Leading (first edge))
  2. trailing edge of the pulse (Trailing (second)edge)

Clock Phase

CPHA - determines on which edge the nodes will read data

  1. CPHA - 0 means that data will be read on the rising edge of each clock signal
  2. CPHA - 1 means that data will be read on the falling edge of each clock signal

SPI Mode

The operation of the master and slave must be coordinated via the SPI operating mode.
The mode is an integer combination of CPOL and CPHA

ModeCPOLCPHA
000
101
210
311

Multi-slave configuratuion

  1. Independent Slaves
  1. Cooperative Slaves / Daisy Chain