Interviews
SPI Interview Questions
Practise the question, then the follow-ups an interviewer asks next.
Start with a Question TreeAI Mock Interview
- 5
- Question trees
- 47
- Follow-ups
- 21
- Wrong answers explained
- 3
- Runnable on a simulator
Flagship Questions · With follow-ups
Question Trees
Each question opens into the follow-ups an interviewer asks next, the wrong answers people give, and what a fresher's and a senior's answer sound like.
-
SPI Modes, CPOL and CPHA
Explain SPI modes 0 to 3. In each mode, which clock edge launches data and which edge samples it? 15 follow-ups · 6 pitfalls · 1 runnable- Likely at Google
- Likely at Qualcomm
- Likely at Analog Devices
-
The Reply Shifted by One Bit
Your controller reads a peripheral's ID register as 52h, but the datasheet says A5h. Writes seem to work. What is your first suspect? 9 follow-ups · 4 pitfalls · 1 runnable -
Sharing MISO Between Peripherals
Three SPI peripherals share one MISO line. What must each do when its chip select is high, and what goes wrong if one does not? 7 follow-ups · 3 pitfalls -
Who Drives the Lanes in EBh
Walk me through a Fast Read Quad I/O (EBh) on a W25Q128JV, clock by clock. Who drives IO0 to IO3 at each point? 7 follow-ups · 4 pitfalls -
The 300-Byte Page Program
Firmware programs a 300-byte buffer into a W25Q128JV starting at a page boundary. Readback shows the first 44 bytes wrong and the next page still erased. Explain. 9 follow-ups · 4 pitfalls · 1 runnable
No question matches these filters.
Quick revision · One flat list
Question Bank
All 21 SPI questions, main and follow-up. Open a track, then a topic. Answer out loud first, then open the short answer.
Jump to a Track
21 questions · 4 topicsSPI
SPI Modes, CPOL and CPHA9
Explain SPI modes 0 to 3. In each mode, which clock edge launches data and which edge samples it? L0L1
CPOL is the clock's idle level. CPHA picks the sampling edge. CPHA 0 samples on the first edge after the clock leaves idle; CPHA 1 samples on the second. The other edge launches the next bit. So modes 0 (CPOL 0, CPHA 0) and 3 (1, 1) sample on rising edges, and modes 1 and 2 on falling edges. With CPHA 0, the first bit must already be on the line when CS falls.
QuestionPractise SPI Modes, CPOL and CPHA →In mode 0 the first edge after CS falls is a sampling edge. When was the first bit launched? L1
At the falling edge of CS. With CPHA 0 there is no launch edge before the first sample. So both sides put bit 7 out as soon as they are selected. They launch every later bit on the trailing edge. A peripheral that waits for a clock edge to drive bit 7 delivers the byte one bit late.
Follow-upPractise Where the First CPHA 0 Bit Comes From →A serial flash supports both mode 0 and mode 3. What actually differs, and does it matter which one you use? L1
Only the clock level while idle, at the CS edges: low in mode 0, high in mode 3. In both, the flash latches input on rising edges and drives output on falling edges. So data transfer is identical. It matters at the frame boundary: the controller must hold the idle clock level when it moves CS. The CS-to-clock setup and hold times still apply.
Follow-upPractise Mode 0 Against Mode 3 →Your controller reads a peripheral's ID register as 52h, but the datasheet says A5h. Writes seem to work. What is your first suspect? L1L2
A clean one-bit shift is the signature of an SPI mode mismatch, not noise. Both sides move one bit per clock but disagree on which edge carries it. The controller samples each bit just before the peripheral launches it, so it gets the previous bit. The lost bit turns up in the next byte. With a mode-0 controller and a mode-1 peripheral, writes can still pass. But their only hold time is the launch delay.
QuestionPractise The Reply Shifted by One Bit →Why is a mode mismatch a shift of exactly one bit, never two? L1
Both sides still move one bit per clock and agree on the number of clocks. They disagree only on which of the two edges in a clock period carries the bit. Those edges are half a period apart. Sampling on the launch edge reads the value from before the launch, which is the previous bit. So every bit lands exactly one place late.
Follow-upPractise Why Exactly One Bit →The mismatched direction passes in your zero-delay simulation. Why might it fail in silicon, and how do you compute the real margin? L2
On the shared edge, the only hold time is the launching side's clock-to-output delay. So a model with no delays always takes the old bit and looks correct. In silicon, hold must beat the receiver's requirement, such as tCHDX of 2 ns on the W25Q128JV. For same-cycle reads, start from half a clock period. Subtract the peripheral's clock-to-output time (tCLQV) and the controller's input setup; the rest is the setup margin.
Follow-upPractise Passing in Simulation, Failing on the Board →You write a passive SPI monitor. How does it know which edge to sample, and what can a checker on the wires assert? L1L2
From configuration, never by guessing: rising when CPOL equals CPHA, falling otherwise. A monitor that infers the mode can be fooled by the very mismatch it should catch. On the wires alone, a checker can assert the idle clock level at CS edges and MISO released while deselected. It can also check stable data on the sample edge, whole bytes on writes and CS-to-clock times. Whether the bytes are right needs a reference model.
Follow-upPractise How an SPI Monitor Picks Its Edge →You verify a QSPI flash controller that does reads, page programs and erases. What is in your bench, and which bugs would still escape? L2L3
Use a wire monitor for every supported mode and lane width. Add wire checks that need no data: idle level, MISO and IO release, CS timing and whole bytes on writes. A strict flash model refuses what the datasheet forbids: programs without WEL, quad reads with QE clear, commands while BUSY. A scoreboard compares readback with a reference memory. Bugs escape through a lenient model, page-wrap writes, off-by-one dummy counts and turnaround timing.
Follow-upPractise Verifying an SPI Flash Controller →Prove it: how do you show that your QSPI bench catches each class of fault, not just that the tests pass? L2L3
Plant one fault per class, such as a missing WEL, a late IO release or a page-wrap error. Run every test against every fault and record which check fires. A fault with no mark is a hole, so add a program for it. On the lesson bench the wire checker caught 1 fault of 11, and readbacks caught the rest.
Follow-upPractise Showing the Flash Bench Catches Each Fault →Sharing MISO Between Peripherals3
Three SPI peripherals share one MISO line. What must each do when its chip select is high, and what goes wrong if one does not? L1
A deselected peripheral must put MISO in high impedance, so only the selected one drives it. The W25Q128JV floats its outputs whenever /CS is high. If a deselected device keeps driving, two outputs fight. Simulation shows x on the bits where they disagree. A board shows mid-rail levels, wrong bits and extra current. Clock, MOSI and MISO are shared; each device has its own active-low select.
QuestionPractise Sharing MISO Between Peripherals →Compare one chip select per device with a daisy chain. L1L2
Separate selects cost one pin per device, but let you talk to any device alone, at its own mode and length. A daisy chain uses one select, and each device's output feeds the next device's input. So the chain is one long shift register, and every update shifts through every device. One broken device breaks the chain, and every device must support pass-through. It suits strings of identical parts, such as LED drivers or shift registers.
Follow-upPractise Separate Selects or a Daisy Chain →How soon after one select rises may the controller select another device and read it? L2
The first device needs its output-disable time to let go of MISO: 7 ns maximum (tSHQZ) on the W25Q128JV. The next device's first driven bit must come later than that. The same device also has its own minimum deselect time before it accepts a new command. On that flash it is 10 ns after a read and 50 ns after a program, erase or write.
Follow-upPractise Switching from One Device to the Next →Who Drives the Lanes in EBh5
Walk me through a Fast Read Quad I/O (EBh) on a W25Q128JV, clock by clock. Who drives IO0 to IO3 at each point? L2
The controller sends EBh on IO0 alone for 8 clocks. Then it sends the 24-bit address on all four lanes in 6 clocks, and the mode byte in 2 more. Then come 4 dummy clocks, in which the controller must release the lanes. From clock 20 the flash drives one byte every 2 clocks, high nibble first, with the top bit on IO3. QE in status register 2 must be set, because IO2 and IO3 replace the /WP and /HOLD pins.
QuestionPractise Who Drives the Lanes in EBh →Read Data (03h) has no dummy clocks. Why do the fast reads add them? L1L2
The flash needs time to fetch the first byte after the last address bit. Read Data (03h) gets that time by running slowly: on the W25Q128JV it is limited to 50 MHz. Fast Read (0Bh) adds eight dummy clocks so the whole frame can run at the full rated clock. That is 133 MHz in the 3.0 to 3.6 V range. The quad I/O read sends the mode byte and then only four dummy clocks.
Follow-upPractise Why Dummy Clocks Exist →What if the controller sends six dummy clocks instead of eight for Fast Read (0Bh)? L1L2
The flash drives data only after its eighth dummy clock. The controller starts sampling two clocks early, so it reads two junk bits first. Every byte it returns is then shifted by two bits. Check the dummy count per command, because the quad reads use different counts.
Follow-upPractise Too Few Dummy Clocks on a Fast Read →The controller releases IO0 to IO3 one clock late, after the first data clock. What do you see, and how would your bench catch it? L2
Both drivers are on during the first data clock. Simulation shows x on lanes where they disagree; the board shows mid-rail levels and wrong bits. A bench catches it with a wire rule: no lane has two drivers. Or it checks that the controller's output enables are off before the first data clock. Waiting for a data mismatch is not enough, because matching bits hide the fight.
Follow-upPractise Releasing the Quad Lanes Late →A CPU executes in place from this flash with a 32-byte cache line. What does one miss cost, and does burst wrap make it cheaper? L2L3
One EBh read of the line: 8 instruction, 6 address, 2 mode, 4 dummy and 64 data clocks, 84 in all. Burst wrap, set with 77h, does not reduce that. It starts at the byte that missed and wraps within the aligned section. So the CPU can resume while the rest of the line streams in.
Follow-upPractise The Cost of an XIP Cache Miss →The 300-Byte Page Program4
Firmware programs a 300-byte buffer into a W25Q128JV starting at a page boundary. Readback shows the first 44 bytes wrong and the next page still erased. Explain. L2L3
Page Program writes within one 256-byte page. The low address byte wraps inside the page, so bytes 256 to 299 overwrite bytes 0 to 43. The next page is never touched. The driver must split writes at page boundaries. It must send Write Enable (06h) before every program, because WEL clears when a program finishes. It must also raise CS only after a whole byte, and poll BUSY before the next command.
QuestionPractise The 300-Byte Page Program →Why does every program or erase need its own Write Enable, and how does firmware know the operation has finished? L1L2
Write Enable (06h) sets WEL, a guard against stray writes. The flash clears it after every program, erase or status write, so each one needs a fresh 06h. After CS rises, the operation runs on its own for milliseconds. Firmware polls status register 1 with 05h until BUSY, bit 0, reads 0. While BUSY, the flash ignores everything except status reads and suspend.
Follow-upPractise WEL and BUSY →Walk me through how the page-wrap bug escaped your flash-model tests and what you would change. L2L3
The model shared the driver's wrong belief, a linear address. So the two agreed, and the test checked nothing the datasheet says. Fix the model first: feed it stimulus the datasheet forbids or defines unusually, and expect the datasheet's result. Examples are a program past a page, a program without 06h and a quad read with QE clear. Then cover page offset × length, including lengths that cross the boundary.
Follow-upPractise How the Page Bug Escaped →What if firmware programs a location that already holds data, without erasing first? L1L2
The datasheet defines Page Program only on erased locations, which read FFh. So the result is not something to rely on. In practice, programming can only clear bits, never set them. To get 1s back you must erase, and the smallest erase on this flash is a 4 KB sector. So updating one byte means a read, a sector erase and a reprogram.
Follow-upPractise Programming over Old Data →Your Review Queue
Saved review reminders are coming soon.