What does SPI stand for and what is its main purpose?
SPI stands for Serial Peripheral Interface. It is used to transfer data between microcontrollers and peripheral devices quickly and efficiently.
Click to reveal answer
beginner
List the four main signals used in SPI communication.
The four main signals are: 1. SCLK (Serial Clock) 2. MOSI (Master Out Slave In) 3. MISO (Master In Slave Out) 4. SS (Slave Select)
Click to reveal answer
beginner
Describe the sequence of steps in an SPI data transfer.
1. Master pulls SS low to select the slave. 2. Master generates clock pulses on SCLK. 3. Data is sent bit-by-bit from master to slave on MOSI. 4. Data is simultaneously received from slave to master on MISO. 5. After all bits are transferred, master releases SS high to end communication.
Click to reveal answer
intermediate
Why is SPI considered full-duplex communication?
Because data is sent and received at the same time on separate lines (MOSI and MISO), allowing simultaneous two-way communication.
Click to reveal answer
beginner
In SPI, what role does the Slave Select (SS) line play during data transfer?
The SS line tells the slave device when it should listen and respond. Pulling SS low activates the slave, and releasing it high ends the communication.
Click to reveal answer
Which SPI signal carries data from the master to the slave?
AMOSI
BMISO
CSCLK
DSS
✗ Incorrect
MOSI stands for Master Out Slave In, so it carries data from the master to the slave.
What happens when the master pulls the SS line low?
AIt sends data to the master
BIt stops the clock signal
CIt resets the SPI bus
DIt selects the slave device to start communication
✗ Incorrect
Pulling SS low tells the slave device to listen and prepare for data transfer.
SPI communication is considered full-duplex because:
AIt uses only one wire for data
BData can be sent and received simultaneously
CIt only sends data one way
DIt uses a clock signal
✗ Incorrect
Full-duplex means data flows both ways at the same time, which SPI supports using MOSI and MISO lines.
Which signal provides the timing for data transfer in SPI?
AMOSI
BMISO
CSCLK
DSS
✗ Incorrect
SCLK is the serial clock generated by the master to synchronize data transfer.
During SPI transfer, when is the data considered fully sent?
AAfter all bits are shifted out
BWhen the clock stops toggling
CWhen the master pulls SS high
DWhen MOSI goes low
✗ Incorrect
Data is fully sent after all bits have been shifted out on MOSI and received on MISO.
Explain the step-by-step sequence of an SPI data transfer from start to finish.
Think about how the master controls the communication and how data flows both ways.
You got /5 concepts.
Describe why SPI is called full-duplex and how its signals support this.
Consider how data moves on MOSI and MISO at the same time.
You got /4 concepts.
Practice
(1/5)
1. In SPI communication, what happens during a data transfer sequence?
easy
A. Data is only sent, no data is received.
B. Data is sent and received simultaneously, one byte at a time.
C. Data is received first, then sent after completion.
D. Data is sent in large blocks without waiting for response.
Solution
Step 1: Understand SPI full-duplex nature
SPI sends and receives data simultaneously, byte by byte.
Step 2: Confirm data transfer behavior
Each byte sent triggers a byte received at the same time.
Final Answer:
Data is sent and received simultaneously, one byte at a time. -> Option B
Quick Check:
SPI full-duplex = simultaneous send/receive [OK]
Hint: Remember SPI sends and receives one byte at a time simultaneously [OK]
Common Mistakes:
Thinking SPI only sends data without receiving
Assuming data is received after all sending completes
Believing SPI transfers data in large blocks
2. Which of the following code snippets correctly waits for SPI transfer completion before reading received data?
easy
A. while(!(SPI_SR & SPI_SR_RXNE)); uint8_t data = SPI_DR;
B. uint8_t data = SPI_DR; while(!(SPI_SR & SPI_SR_RXNE));
C. while(SPI_SR & SPI_SR_BSY); uint8_t data = SPI_DR;
D. while(!(SPI_SR & SPI_SR_TXE)); uint8_t data = SPI_DR;
Solution
Step 1: Identify the correct flag for received data ready
SPI_SR_RXNE indicates data received and ready to read.
Step 2: Confirm waiting loop and reading order
Wait until RXNE is set, then read SPI_DR to get received byte.
Final Answer:
while(!(SPI_SR & SPI_SR_RXNE)); uint8_t data = SPI_DR; -> Option A
Quick Check:
Wait RXNE flag before reading data [OK]
Hint: Wait for RXNE flag before reading SPI data register [OK]
Common Mistakes:
Waiting for TXE instead of RXNE
Reading data before checking RXNE flag
Waiting for BSY flag incorrectly
3. Given the following code snippet, what will be the content of the array received[3] after execution?
Each byte sent causes a byte to be received simultaneously from the slave device.
Step 2: Analyze received array assignment
received[i] stores the byte read from SPI_DR after waiting for RXNE flag.
Final Answer:
Data received from SPI slave during transfer -> Option C
Quick Check:
Received array = slave response bytes [OK]
Hint: Received data is from slave, not the sent bytes [OK]
Common Mistakes:
Assuming received data equals sent data
Ignoring that SPI_DR reads slave response
Expecting zeros or uninitialized values
4. Identify the error in this SPI data transfer loop:
for(int i = 0; i < 4; i++) {
SPI_DR = data[i];
received[i] = SPI_DR;
while(!(SPI_SR & SPI_SR_RXNE));
}
medium
A. Loop counter exceeds array size.
B. Not sending data before reading.
C. Missing SPI enable command.
D. Reading SPI_DR before waiting for RXNE flag.
Solution
Step 1: Check order of reading SPI_DR and waiting for RXNE
The code reads SPI_DR before waiting for RXNE flag, which is incorrect.
Step 2: Correct sequence for SPI read
Must wait for RXNE flag before reading SPI_DR to get valid received data.
Final Answer:
Reading SPI_DR before waiting for RXNE flag. -> Option D
Quick Check:
Wait RXNE before reading SPI_DR [OK]
Hint: Always wait RXNE flag before reading SPI_DR [OK]
Common Mistakes:
Reading SPI_DR too early
Ignoring RXNE flag status
Assuming data is ready immediately after writing
5. You want to send an array of 5 bytes over SPI and store the received bytes simultaneously. Which code snippet correctly implements this transfer sequence?