1. What is SPI?
SPI is a full-duplex, high-speed, synchronous serial communication protocol.
Uses a master–slave model (one master, one/multiple slaves).
Signals:
SCLK → Clock generated by master.
MOSI → Master Out, Slave In.
MISO → Master In, Slave Out.
CS (Chip Select) → Active-low, selects the target slave.
👉 Example: MCU (master) ↔ Flash Memory (slave).
2. SPI Modes
SPI has 4 modes, determined by two parameters:
CPOL (Clock Polarity): idle state of clock.
CPOL = 0 → SCLK idle low.
CPOL = 1 → SCLK idle high.
CPHA (Clock Phase): edge used for sampling and shifting data.
CPHA = 0 → Data sampled on the first clock edge.
CPHA = 1 → Data sampled on the second clock edge.
Mode CPOL CPHA Clock Idle Sampling Edge Shifting Edge
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
👉 Peripheral datasheets usually specify which SPI mode they support (e.g., EEPROM
might need Mode 0).
3. Multi-Master SPI Operation
Unlike I²C (which was designed for multi-master), SPI is inherently single-master.
But multi-master SPI is possible with restrictions:
Challenges:
Clock Line (SCLK) → Each master generates its own clock → conflicts can occur.
Bus Arbitration → No built-in arbitration (unlike I²C).
Chip Select Lines → Must be managed so that only one master talks to a slave at a
time.
Approaches:
Master Arbitration in Firmware/Hardware
Use a bus arbiter (logic or FPGA) to decide which master drives the bus.
Only the active master drives SCLK, MOSI, CS.
Three-State Buffers
Masters use tri-state drivers on SCLK, MOSI, CS.
Only the bus-winning master enables its drivers.
Multi-Master Example
Suppose you have 2 MCUs and 1 Flash memory.
Both MCUs want to access the Flash.
An arbiter decides which MCU takes control; the other keeps its pins Hi-Z.
👉 Because of complexity, in practice SPI multi-master is rarely used. Instead:
One MCU acts as system master, other MCUs communicate with it via SPI or UART/I²C.
4. Example Use Cases
Mode 0 SPI Flash: MCU (master) writes/reads bytes to Flash memory.
Mode 3 Display Driver: Display IC expects idle-high clock, data sampled on rising
edge.
Multi-Master Edge Case: Two DSPs sharing one ADC via SPI → require arbitration.
5. Visual Summary
Master (MCU) Slave (e.g., EEPROM)
MOSI -------------------> MOSI
MISO <------------------- MISO
SCLK -------------------> SCLK
CS -------------------> CS (Active Low)
Modes (CPOL, CPHA):
Mode 0: Idle Low, Sample Rising.
Mode 1: Idle Low, Sample Falling.
Mode 2: Idle High, Sample Falling.
Mode 3: Idle High, Sample Rising.
✅ Summary:
SPI = fast, full-duplex, master-driven protocol.
4 modes (CPOL/CPHA combinations).
Multi-master possible but not elegant → needs arbitration & tri-state handling.
Do you want me to also make you a timing diagram of all 4 SPI modes (with SCLK,
MOSI, MISO, sampling points) so it’s easier to visualize?
ChatGPT c