SPI or Serial Peripheral Interface is a three-wire (or, depending on how you look at it, four-wire) bus used to communicate data between a master device (usually a microcontroller) and one or more slave devices (such as sensors, displays, keypads, et cetera).


The wires used for communication are very straightforward compared to more complicated busses such as I2C or USB:

  • MOSI (Master Out, Slave In) -- This line sends data from the master to the slave. Often pronounced "mosey", though I've also heard "mossy".
  • MISO (Master In, Slave Out) -- This line sends data from the slave to the master. Usually pronounced just like the Japanese flavoring miso.
  • SCK (Serial ClocK) -- This line carries the clock signal. The clock signal is a square wave sent by the master that tells the slave when each bit begins and ends. The details of this can change, but for example, a bit may begin when the SCK line goes high (meaning it has a positive voltage of around +5 volts), and end when the line goes low (meaning its voltage is equal to, or very close to, ground, or 0 volts). I usually just pronounce it "ess see kay", although I've heard "sick" as well.
  • SS (Slave Select) -- This line tells the slave that the master is talking to it. There is one SS line for each slave connected to the master. When the master wants to talk to a single slave device, it pulls that device's SS line low (the lines are high by default).
Sound confusing? Here's a crude ASCII art diagram of a SPI bus with one master and three slaves. A plus (+) indicates a wire connection, an hash sign (#) indicates a connection into a master or slave, and a pipe (|) indicates a place where wires cross each other but are not connected to one another.
|         MOSI #--------------+-----------+-----------+
|              |              |           |           |
|         MISO #------------+-|---------+-|---------+ |
|              |            | |         | |         | |
|          SCK #----------+-|-|-------+-|-|-------+ | |
|              |          | | |       | | |       | | |
|     SPI      |       .--#-#-#--. .--#-#-#--. .--#-#-#--.
|   Master     |       | Slave 1 | | Slave 2 | | Slave 3 |
|              |       '----#----' '----#----' '----#----'
|              |            |           |           |
|          SS1 #------------+           |           |
|              |                        |           |
|          SS2 #------------------------+           |
|              |                                    |
|          SS3 #------------------------------------+

Now say the master wants to send information to Slave 2. It pulls SS2 low, while leaving SS1 and SS3 high. This tells Slave 2 "hey, listen up", while telling the others "ignore this".

Next the master starts sending data out the MOSI line, along with a square wave on the SCK line. Here is an example of how the binary sequence "11010100" might look:

       1    .-------.   .---.   .---.
MOSI        |       |   |   |   |   |
       0 ---'       '---'   '---'   '-------------
              1   1   0   1   0   1   0   0 
       1     .-. .-. .-. .-. .-. .-. .-. .-.
SCK          | | | | | | | | | | | | | | | |
       0 ----' '-' '-' '-' '-' '-' '-' '-' '------

There you have it: the master has sent one byte to the slave.

Now, you might wonder, how does the slave send data back? Well, the slave can't just send data whenever it wants to. The master has to give it the clock signal, so the slave knows when to send each bit. Usually, you'll have something like the master sending a message to the slave, something like "Tell me the contents of register X", and then the slave responding "Register X contains the value Y, sir!"


SPI's primary advantage over more complex buses like I2C and USB is its simplicity. There's no special protocol required over the MISO/MOSI lines, no handshaking, just raw bits. This is also its flaw, because no protocol means each slave needs a dedicated Slave Select line to know when it is being addressed. This can be cut down significantly with a multiplexer (which might let you use, for example, three lines instead of eight), but it still means a SPI bus with only one slave on it needs four pins, and one with eight slaves will need six pins at the bare minimum. I2C and USB can do far more with just two pins.


An easier question might be to ask where it isn't; SPI is used in all sorts of embedded systems across the planet, from televisions to toys, computers to cooktops. If it has a microcontroller in it, there's a fair chance SPI is being used for something.