
The clock
A peripheral cannot send a single bit on its own. Every bit that moves on an SPI bus moves on a tick of the clock the controller drives, and when the controller stops the clock, everything stops with it.
On a serial port both ends keep their own clock and agree on a speed. On SPI there is one clock, and the controller owns it. It is the SCK wire, and only the controller drives it.
One tick, one bit
Each cycle of SCK moves one bit along MOSI and one along MISO. The wires carry no start marker and no stop marker, so the clock is the only thing that says when a bit is valid. A byte is eight ticks. Nine ticks is a byte and one bit of the next.
The controller does not have to run the clock evenly. It can stop after any tick and carry on later, and the peripheral waits, holding its place in the byte. A peripheral does not mind a slow clock. It minds one that is too fast for it, which is lesson nine.
The peripheral cannot ask
Since the peripheral does not drive SCK, it cannot say that it has something to send. A peripheral with a reading ready can put its first bit on MISO, but the bit does not go anywhere until the controller ticks. If the controller never ticks, the reading sits where it is. The controller has to ask, by clocking, and only then does an answer come back.
This is also why a faster clock means a faster belt and nothing more. Nothing else on the bus changes speed. The same bits go past, sooner.
What it costs
Because a bit is defined by a tick, a wrong number of ticks is a wrong byte. A single extra pulse on SCK from noise, a long wire or a floating pin shifts every following bit by one place, and the byte that arrives is close to the right one and not equal to it. Nothing on the bus reports it. On most parts, raising CS ends the transaction and starts the count again, which is the usual way to recover.
Common mistakes
- Waiting for the peripheral to send. It cannot. Clock it, or nothing comes.
- Counting the wrong number of ticks. Eight ticks is one byte, and a ninth starts another.
- Letting SCK float while the controller starts up. A stray edge before the first byte can leave the peripheral out of step.
Edit this page — content/fundamentals/spi/the-spi-clock.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.