SPI communication based learning

SPI is an acronym for "Serial Peripheral Interface", namely, "Serial Peripheral Interface", Motorola has introduced a serial interface communication protocol.

Wiring diagram:

SPI bus can learn the principles of I2C, difference between the two following points:

(1) I2C only two signal lines, one the SDA data line, a clock line SCL; SPI has four signal lines: MISO, MOSI, SCK, and NSS.

  • MOSI: Master Output Slave Input, output master / slave input. Transmitting data output from the host to the slave, the host data.
  • MISO: Master Iutput Slave Output, the master input / output from the device. The data output from the slave to the host, receive data.
  • SCK: a clock signal line for synchronizing communication.
  • NSS: chip select lines, for selecting from the communication apparatus, can also be CS (active low) FIG. Each device has an separate from the NSS signal line, to select a master device with which the communication line by a device of the NSS is set low. Therefore NSS SPI communication lines at a low level is set as a starting signal to NSS level line is pulled to a stop signal.

(2) I2C communication is half-duplex, SPI communication is a full duplex to. I2C i.e. not simultaneously transmit and receive data, and may SPI.

(3) I2C device relies on the address to select from, and each transceiver has a response signal; rely on the SPI chip select signal to select from the device, there is no response signal, the transceiver casually.

 

work process:

In the chip select line is pulled low NSS machine on each clock cycle and a data sampling trigger, when NSS is pulled finally, the communication ends.

The figure shows the operating mode is triggered SCK rising edge, falling edge sampling. There are four operating modes SPI practical, depending on the state "the CPOL Clock Polarity" and "CPHA Clock Phase", as follows.

 

The main difference is the SPI four operating modes of SCK bus idle state and the data sampling time .

如果CPOL被清0,则SCK在空闲状态保持低电平,反之被置1则保持高电平;如果CPHA位被清0,则在SCK每个时钟周期的第1个边沿(奇数边沿)进行数据位采样,反之被置1则在SCK每个时钟周期的第2个边沿(偶数边沿)采样。

下表展示了SPI四种工作模式的状态:

 

数据传输时从最高位开始,一位一位传输。


 

参考文章:

https://zhuanlan.zhihu.com/p/27376153

https://zhuanlan.zhihu.com/p/27462822

https://zhuanlan.zhihu.com/p/33356830

 

Guess you like

Origin www.cnblogs.com/banmei-brandy/p/11277822.html