vimwiki/tech/SPI.wiki

46 lines
1.4 KiB
Plaintext

= SPI =
SPI or Serial peripheral interface is the standard often used as a form of
interchip communication on boards, and in embedded devices.
See https://www.youtube.com/watch?v=MCi7dCBhVpQ
== Layout ==
Each device, the master and slave (often microcontroler as master and
peripheral/sensor as slave) have four pins
* SCK - Serial Clock
* CS - Chip select (active low)
* SDI - Serial data in
* SDO - Serial data out
NOTE serial data * is from the persepctive of the device (SDI on master is
connected to SDO on slave and vice versa).
SDO on the master to SDI on the peripherial is often called MOSI (Master out
Slave in), and the inverse is often called MISO (Master in Slave out).
Some chips may only have a MOSI, as some devices do not create data to send
back to the master.
== Sending data ==
On the *rising edge* of the clock, each device reads what is currently set on
the respective input port. The chip must also have its output set before the
rising edge, to ensure that the device will receive the data it intends to
send. All of this only occurs when CS is set low. This is known as *mode 0*
Ther are several other modes. All of the modes are detailed in the table below.
| Mode | CLK default | Send on | Sample on |
--------------------------------------------
| 0 | LOW | falling edge | rising edge |
| 1 | LOW | rising edge | falling edge |
| 2 | HIGH | rising edge | falling edge |
| 3 | HIGH | falling edge | rising edge |