Serial Communication : SPI

In the last post we discussed UART , which was a type of serial communication between devices. In this post we are going to talk about another type of serial communication which is SPI. SPI communication is used by a number of devices like the RFID card reader, SD card module, etc.

Introduction to SPI
SPI stands for Serial Peripheral Interface. It was developed by Motorola in 1979. Device communicating via SPI are in master-slave relationship. The master as the name suggests is the controlling device and the slave is the one who takes instruction from the master. There can a number of slaves under one master.


MOSI : Master Output Slave Input - Line for master to send the data to the slave.
MISO : Master Input Slave Output - Line for slave to send data to the master.
SCLK : Clock - Line for the clock signal
SS/CS : Slave select/Chip Select : Line for the master to select the slave to send data to.

So, at least four wires are required for this communication. More wires are required if there is more than one slave. Maximum speed is up to 10Mbps. The type of communication is synchronous. There can only be one master but an infinite number of slaves.

If we look at the Uno, pin 13 is for SCLK, pin 12 for MISO, pin 11 for MOSI and pin 10 for SS/CS. One unique feature about it is that any number of bits can be communicated in a continuous stream unlike the UART type of communication.

Multiple slaves can be connected to a single master in two ways. If master has multiple slave select pins, the slaves can be connected in parallel. If not, the slaves are connected in daisy-chain as shown below.



How it Works ?
Signal Clock :  It is the master who controls the clock signal. The speed of data transfer depends on the frequency of the clock since one bit of data is transferred in each clock cycle. It is the clock which synchronizes the output of data bits from the master and sampling of data by the slave.

The clock signal can be modified by two properties which is clock polarity and clock phase. The clock polarity can be set by the master to allow bits to be output and sampled either on rising  edge( positive polarity) or falling edge (negative polarity) of the clock pulse. The clock phase can be set to output and sample data on either first or second edge of the clock signal regardless whether it is rising or falling. So, there are four possible clock configurations.

Multiple Slaves by Slave Select : The master can choose which slave to talk to by setting the slave`s SS/CS line to low voltage level. In normal state, it is kept high.

First the master outputs the clock signal through the SCLK line. Then the master pulls the slave select pin of a particular slave low to activate that slave. Then the master sends data bit by bit to the slave through the MOSI line. The data is usually sent with most significant bit first. Since it is bi-directional, the slave can also send data to the master through the MISO line. This data is usually sent with least significant bit first..

Comments

Popular posts from this blog

The move_base ROS node

Three Wheeled Omnidirectional Robot : Motion Analysis

Overview of ATmega328P