Serial Peripheral Interface (SPI)
Chip Select (CS)
There's one last line you should be aware of, called CS for Chip Select. This tells the peripheral that it should wake up and receive / send data and is also used when multiple peripherals are present to select the one you'd like to talk to.
The CS line is normally held high, which disconnects the peripheral from the SPI bus. (This type of logic is known as “active low,” and you’ll often see used it for enable and reset lines.) Just before data is sent to the peripheral, the line is brought low, which activates the peripheral. When you're done using the peripheral, the line is made high again. In a shift register, this corresponds to the "latch" input, which transfers the received data to the output lines.
There are two ways of connecting multiple peripherals to an SPI bus:
- In general, each peripheral will need a separate CS line. To talk to a particular peripheral, you'll make that peripheral's CS line low and keep the rest of them high (you don't want two peripherals activated at the same time, or they may both try to talk on the same POCI line resulting in garbled data). Lots of peripherals will require lots of CS lines; if you're running low on outputs, there are binary decoder chips that can multiply your CS outputs.
- On the other hand, some parts prefer to be daisy-chained together, with the POCI (output) of one going to the PICO (input) of the next. In this case, a single CS line goes to all the peripherals. Once all the data is sent, the CS line is raised, which causes all the chips to be activated simultaneously. This is often used for daisy-chained shift registers and addressable LED drivers.
Note that, for this layout, data overflows from one peripheral to the next, so to send data to any one peripheral, you'll need to transmit enough data to reach all of them. Also, keep in mind that the first piece of data you transmit will end up in the last peripheral.
This type of layout is typically used in output-only situations, such as driving LEDs where you don't need to receive any data back. In these cases you can leave the controller's POCI line disconnected. However, if data does need to be returned to the controller, you can do this by closing the daisy-chain loop (blue wire in the above diagram). Note that if you do this, the return data from peripheral 1 will need to pass through all the peripherals before getting back to the controller, so be sure to send enough receive commands to get the data you need.