spi

SPI bit transmission, how does it really works?


I have go through multiple websites to find more info on the SPI protocol communication, and found a contradiction between two of these explanations:

  1. The bit transmission starts with master sending LSB first to slave and continue to exchange 1 bit at a time. The LSB on master will become the MSB of slave, and LSB of slave becomes MSB of master. The LSB of master will continue to shift until it becomes the LSB of slave. The image below will show how the order will conduct:

    enter image description here

    Before bit transmission

    enter image description here

    After 1 bit transmission

  2. The first byte send to the slave are in MSB first and the slave will response it back in LSB first format.

    enter image description here

    enter image description here

I am confused on how this SPI protocol works or really the LSB or MSB is not important? It is just to provide some sort of agreement between master and slave so they understand what bit is transferred first. If I were to do the SPI comm would I need to consider how the bit transmission is being sent(MSB/LSB) or will it be transparent to the user?


Solution

  • Explanation 1 is a particular implementation of the SPI protocol, namely with shift registers. But that's only one way of doing. If shift registers are used, the bits are fed in at one end of the register, say the MSB end, and then shifted through to the other end. The images just show a temporary state. The MCU or CPU will read or write an entire byte after all bits have been shifted. By then, the MSB bit is in the MSB position, and the LSB bit is in the LSB position.

    So the entire explanation is about the implementation, not about the SPI protocol.

    Explanation 2 looks to me as if two pictures from different SPI setups have been put into a context that will never exists. SPI can be run in MSB-first or LSB-first mode. But I've never seen that the master uses a different mode than the slave. So these two pictures are from two different setups.