🔌SPI Architecture and Signals
If SPI communication were explained using only four signal names, it would seem incredibly simple.
Just connect SCLK, MOSI, MISO, and Chip Select, and communication works.
In reality, those signals only make sense when viewed as part of a larger architecture.
Before understanding what each signal does, we need to answer a more important question:
Who controls SPI communication?
The answer leads us directly to the SPI Master-Slave architecture.
Why Does SPI Need a Master and a Slave?
Imagine a classroom where every student tries to ask and answer questions at the same time.
The result would be chaos.
Someone must control the conversation.
Digital systems face the same challenge.
A microcontroller may be connected to:
-
Sensors
-
Flash memories
-
ADCs
-
DACs
-
Displays
If every device could start transmitting whenever it wanted, communication would quickly become unreliable.
SPI solves this problem by assigning clear responsibilities to each device.
One device controls communication.
The other device responds.
This structure is known as the Master-Slave architecture.
Understanding the Master-Slave Architecture
A basic SPI system contains:
-
One Master
-
One Slave
The master initiates communication.
The slave waits until communication is requested.
A simplified SPI connection looks like this:
+-------------+
| Master |
+-------------+
| | | |
| | | |
SCLK MOSI MISO CS
| | | |
v v ^ v
+-------------+
| Slave |
+-------------+
Notice something important.
Communication does not begin when the slave wants to communicate.
Communication begins when the master decides to communicate.
This is one of the defining characteristics of SPI.
Responsibilities of the Master
The master controls the entire SPI transaction.
Think of the master as the conductor of an orchestra.
The conductor decides when everyone starts and stops playing.
Similarly, the SPI master controls communication timing.
The master is responsible for:
Generating the Clock
The master creates the Serial Clock (SCLK).
This clock synchronizes communication between devices.
Without the clock, data cannot be transferred reliably.
Selecting the Slave
The master activates the Chip Select signal to choose which slave should communicate.
Sending Data
The master sends commands and data to the slave using MOSI.
Receiving Data
The master receives information from the slave using MISO.
Because the master performs all these tasks, it effectively controls the SPI bus.
Responsibilities of the Slave
The slave has a simpler role.
Instead of controlling communication, it responds to requests from the master.
The slave:
-
Monitors Chip Select
-
Receives commands
-
Processes requests
-
Returns data when required
A key point is that the slave does not generate the clock.
It uses the clock provided by the master.
This simplifies slave hardware and helps keep communication synchronized.
Understanding SCLK
SCLK stands for Serial Clock.
This signal acts as the timing reference for communication.
Direction:
Master -----> Slave
Every SPI transaction depends on this clock.
When the clock is active, data can be transferred.
When the clock stops, communication stops.
You can think of SCLK as the heartbeat of SPI communication.
It keeps both devices operating in sync.
Understanding MOSI
MOSI stands for:
Master Out Slave In
As the name suggests, MOSI carries information from the master to the slave.
Direction:
Master -----> Slave
Typical information sent through MOSI includes:
-
Commands
-
Configuration settings
-
Memory addresses
-
Data values
For example, a microcontroller may send a command instructing a sensor to provide a temperature reading.
That command travels through MOSI.
Understanding MISO
MISO stands for:
Master In Slave Out
This signal carries information from the slave back to the master.
Direction:
Slave -----> Master
Typical information transmitted through MISO includes:
-
Sensor measurements
-
Status information
-
Memory contents
-
ADC conversion results
If a sensor measures a temperature of 25°C, that value is returned to the master through MISO.
Together, MOSI and MISO allow SPI to support full-duplex communication, meaning both devices can exchange data simultaneously.
Understanding Chip Select
Chip Select (CS) determines which slave device should participate in communication.
Direction:
Master -----> Slave
When Chip Select becomes active:
-
The slave listens
-
Communication begins
When Chip Select becomes inactive:
-
The slave ignores bus activity
-
Communication ends
Think of Chip Select as calling someone's name in a crowded room.
Only the person whose name is called responds.
Similarly, only the selected SPI device participates in the transaction.
Physical Connections in SPI
The physical wiring of SPI is straightforward.
A single-slave connection uses four primary signals:
+-------------+
| Master |
+-------------+
| | | |
| | | |
SCLK MOSI MISO CS
| | | |
v v ^ v
+-------------+
| Slave |
+-------------+
Each signal has a dedicated connection.
This dedicated wiring is one reason SPI can achieve high communication speeds.
Unlike some protocols that share data lines, SPI provides separate paths for transmitting and receiving data.
Communication Example
Consider a microcontroller connected to a temperature sensor.
The communication sequence might look like this:
-
The master activates Chip Select.
-
The master generates clock pulses.
-
A read command is sent through MOSI.
-
The sensor processes the request.
-
Temperature data is returned through MISO.
-
Chip Select is deactivated.
Communication is complete.
This same process is used in many SPI-based systems.
Whether communicating with a sensor, Flash memory, or display controller, the basic architecture remains the same.
Debugging Perspective
Many SPI communication problems originate from signal-level issues.
Common examples include:
MOSI and MISO Swapped
The slave never receives valid commands and the master never receives valid responses.
Missing Clock
Without SCLK, communication cannot occur.
Incorrect Chip Select
The wrong device may respond, or no device may respond at all.
Wiring Errors
Loose connections or incorrect routing can create intermittent failures.
Understanding the purpose of each signal often makes debugging much easier.
Interview Questions
Basic
-
What is the role of the SPI master?
-
What is the role of the SPI slave?
-
What do MOSI and MISO stand for?
Intermediate
-
Why does the master generate the SPI clock?
-
What is the purpose of Chip Select?
-
Why is SPI considered a full-duplex protocol?
Advanced
-
Why can SPI achieve high performance despite its simple architecture?
-
What problems occur if multiple devices drive MISO simultaneously?
-
Why does a slave not need to generate its own clock?
🔑 Key Takeaways
-
SPI uses a Master-Slave architecture to organize communication.
-
The master controls communication by generating the clock and selecting devices.
-
The slave responds to commands from the master.
-
SCLK provides synchronization.
-
MOSI carries data from the master to the slave.
-
MISO carries data from the slave to the master.
-
Chip Select determines which device participates in communication.
-
Understanding signal responsibilities is essential for both design and debugging.