Fundamentals/SPI/Four wires and a light
Chapter · SPI

Four wires and a light

Why SPI exists beside I2C, what each of its four wires does, and how a byte goes out while a byte comes back.

  1. 01Why another bus4 minI2C finds a chip by its address and waits for an answer to every byte, which caps it at 1 Mbit/s. SPI drops the address and the answers, sends a byte each way at once, and pays with more wires.
  2. 02Four wires4 minSPI is four wires and no more. Two carry data, one carries the clock, one picks which chip is listening. Most first-day failures with a new SPI part are one of those four on the wrong pin.
  3. 03The clock4 minA 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.
  4. 04One byte4 minA byte on SPI is eight bits sent one per clock tick, most significant bit first on almost every part. A chip that wants the bits the other way round gets a byte that looks like a mirror image of the one you meant.
  5. 05Talking and listening4 minOn SPI every byte the controller sends is a byte it receives. There is no way to only listen, so to read a peripheral you send it something to make the clock run, and what you send is thrown away.
  6. 06Chip select4 minSPI has no addresses, so every peripheral gets a chip select wire of its own. The controller pulls one wire low to say who is being spoken to, and every other peripheral must let go of MISO.

Start at 01 and read down — the order is the order things get easier in. Or take the one with your part in it; every article stands on its own, and links back to whatever it needs.