
More than one device
Peripherals share the clock and the two data wires, and each gets a chip select of its own. A daisy chain saves the pins by threading them into one long shift register, and pays for it in clocks.
A board with a display, a sensor and a flash chip still has one set of SCK, MOSI and MISO wires. All three peripherals hang on them, and chip select tells them apart.
One chip select each
Every peripheral has its own CS wire back to the controller. The controller pulls one low, and only that peripheral listens and drives MISO. The others ignore the clock and leave MISO alone. Three peripherals cost three CS pins, ten cost ten, on top of the three shared wires.
The trap is a peripheral that keeps driving MISO when it is not selected. The W25Q128 datasheet says its output goes high-impedance when /CS is high. Some SD cards do not let go, so check the part.
The daisy chain
The other wiring is a chain. The controller's MOSI goes into the first peripheral. Each peripheral's output goes into the next one's input, and the last one's output comes back to MISO. SCK and one CS are shared by all of them, and the registers become one long shift register.
The Maxim MAX7219 display driver is made for this. Its datasheet says the data into DIN appears at DOUT 16.5 clock cycles later. Each chip takes 16 bits, an address byte and a data byte, so a chain of N chips needs 16 × N clocks, not 8 × N. The first pair sent ends up in the last chip, and the chips take the last 16 bits they hold when the load line rises.
The trade
A chain needs four wires however long it is, and every message is as long as the chain. To change one chip you still send bits for all of them. Separate chip selects cost pins, and let you talk to any one peripheral in the time one message takes.
Common mistakes
- Counting 8 clocks per chip on a MAX7219 chain. It needs 16, and the wrong count puts each byte in the wrong chip.
- Sharing one CS between peripherals that are not chained. They all hear the same bytes, and they answer together on MISO.
- Chaining a peripheral that has no output for the next one. The MAX7219 has DOUT for it; most SPI parts have nothing.
Edit this page — content/fundamentals/spi/more-than-one-device.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.