In SPI, I have a few questions...

I understand how bits are clocked through, but how are bytes are delimited?

Is the slave select pin only required for turning the data output high impedance? Or is it also required for delimiting bytes/words?

Also: I got the impression from what I've read (PIC16f74 datasheet) is SPI can be 3 wire, and there are addressing modes which I'm so confused about I think I'll pretend I didn't read for the moment!

I'm just interfacing a PIC16F with 8 bit flash memory Atmel AT45DB011D, so nothing else on the SPI lines. It also has multi-byte commands, so how does it delimit those?

SPI and using the flash chip are totally new to me, any quick-start guidance would be great!


1 Answer 1


There is no concept of 'delimiting' bytes in SPI. The simple fact that 8 bits have been transmitted constitutes a byte, and the ninth bit would be the first bit of the next byte.

In SPI reception begins when the chip select line is lowered (or raised for some chips). The data is then clocked in one bit at a time into a shift register. As each bit arrives the shift register shuffles all the bits down one.

An SPI chip typically has a fixed shift register size, and is not bound by byte sizes. Some have multiples of 8 bits, which is nice, some have 10 bits, some 17 bits, etc.

If you clock in more than the required number of bits the first bits kind of drop off the end of the shift register and are lost, so if you have a 10 bit shift register, and you can only send multiples of 8 bits (which is common with the PIC chips), then if you send the first byte as 6 bits of 0 followed by 2 bits of data, then a second byte of 8 bits of data, the first 6 bits will be discarded as they drop off the end, and the shift register will only contain the last 10 bits.

Addressing modes are basically taking a few extra bits in the SPI data stream and comparing them to a set of pins tied either high or low on the chip. If they match then the data in the shift register should be acted upon. If they don't then it should be discarded.

A number of SPI chips include a pass-through function where you can chain them together, and as data is clocked into the first chip what is at the end of its shift register, and would normally be discarded, is sent to an output pin. This can then go to the input of the next chip thus passing the data down the line from chip to chip. In this case it is critical to make sure your data is packed into a single stream with no bits that you'd normally discard (can be tricky if the chips don't use multiples of 8 bits).

The number of 'wires' in SPI is misleading at best, as it doesn't really tell you how many real wires are needed.

Typically you have:

  • Clock
  • Chip Select
  • Data in
  • Data out

Some chips may not have a data out, and they only accept data into them. Some combine the in and the out together, so you have to split them apart somehow - either in software if you can, or in hardware.

If you have both data in and data out, then SPI can work in full duplex mode (but doesn't always) where as you clock data into the shift register, data is also being clocked out for you to read. This isn't often used, as most systems rely on a command being sent before a response can occur. There is sometimes another line to signal when the data has finished being sent to the SPI device and the response should be sent. More often, though, it happens when a certain number of bits have been received, or a certain combination of bits. It is common to pad the start of a transmission with 0 then signal the device to start receiving with a start bit.

There are many ways of doing it, and no one ever seems to do the same thing as anyone else - or even as themselves sometimes.

SPI defines how the data is transferred, not how the data is formed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.