DEV Community

Raks2000
Raks2000

Posted on

BASICS OF SPI COMMUNICATION PROTOCL

Hello Readers,
I am Rakshith M working as a Junior Software engineer in Luxoft India. While working in one of the projects I got interest on learning SPI communication protocol, so I have written this article based on my knowledge.

INTRODUCTION TO SPI COMMUNICATION
SPI is a common communique protocol utilized by many exceptional devices. For example, SD card reader modules, RFID card reader modules, and a couple of. Four GHz wireless transmitter/receivers all use SPI to speak with microcontrollers.
One precise benefit of SPI is the truth that records may be transferred without interruption. Any variety of bits can be sent or obtained in a non-stop circulate. With I2C and UART, facts are dispatched in packets, restricted to a specific range of bits. Start and forestall conditions define the beginning and stop of every packet, so the statistics is interrupted during transmission.

Image description

MOSI: MOSI stands for Master Output Slave Input. It is used to send records from the grasp to the slave.

MISO: MISO stands for Master Input Slave Output. It is used to send facts from the slave to the grasp.

SCK or SCLK (Serial Clock): It is used to the clock signal.

SS/CS (Slave Select / Chip Select): It is used by the grasp to send records by using choosing a slave.

Image description

Master – Out / Slave – In or MOSI, as the name indicates, is the information generated with the aid of the Master and acquired by the Slave. Hence, MOSI pins on each the grasp and slave are related together. Master – In / Slave – Out or MISO is the records generated with the aid of Slave and must be transmitted to Master.
MISO pins on both the grasp and slave are ties together. Even although the Signal in MISO is produced by means of the Slave, the road is managed with the aid of the Master. The Master generates a clock signal at SCLK and is supplied to the clock input of the slave. Chip Select (CS) or Slave Select (SS) is used to choose a selected slave via the master.
Since the clock is generated by using the Master, the go with the flow of facts is controlled by using the master. For every clock cycle, one bit of records is transmitted from grasp to slave and one bit of information is transmitted from slave to grasp.
This system occurs simultaneously and after eight clock cycles, a byte of information is transmitted in each direction and for this reason, SPI is a full – duplex verbal exchange.
The tool that generates the clock signal is called the main. Data transmitted between the main and the sub node is synchronized to the clock generated with the aid of the main. SPI devices help a whole lot higher clock frequencies in comparison to I2C interfaces. Users need to seek advice from the product statistics sheet for the clock frequency specification of the SPI interface.
The chip picks out signal from the primary is used to choose the sub node. This is normally an energetic low sign and is pulled high to disconnect the sub node from the SPI bus. When a couple of sub nodes are used, a man or woman chip pick sign for each sub node is required from the main. In this text, the chip choose signal is usually a lively low signal.
MOSI and MISO are the statistics strains. MOSI transmits records from the primary to the sub node and MISO transmits facts from the sub node to the principle.

Data Transmission

Image description

To begin SPI communique, the primary ought to ship the clock sign and choose the sub node by allowing the CS sign. Usually, chip choose is an active low sign; as a result, the principle must ship a good judgment 0 in this sign to choose the sub node. SPI is a full-duplex interface; both predominant and sub node can ship statistics on the equal time through the MOSI and MISO traces respectively. During SPI communication, the information is concurrently transmitted (shifted out serially onto the MOSI/SDO bus) and acquired (the information on the bus (MISO/SDI) is sampled or read in). The serial clock facet synchronizes the shifting and sampling of the data. The SPI interface offers the consumer with flexibility to pick out the growing or falling edge of the clock to sample and/or shift the data. Please confer with the device facts sheet to determine the wide variety of statistics bits transmitted the usage of the SPI interface.

The SPI flow is as follows:

  1. The SPI master first pulls the SS or CS line low to inform the SPI slave that communication starts off evolved.
  2. The host sends the SCLK clock sign to tell the slave of the upcoming examine and write operations. The SCLK clock sign right here is decided through the SPI mode whether it's miles active at high degree or at low stage, that allows you to be delivered later.

Image description

  1. The host (Master) writes the information to be sent to the sending facts buffer vicinity (Memory), the buffer vicinity passes through the shift register (zero~7), and the serial shift register shifts the byte bit by bit thru the MOSI sign line. Send out to the slave, and on the equal time, the data acquired through the MISO interface is moved to the receiving buffer separately thru the shift sign up.
  2. The slave (Slave) additionally returns the contents of its serial shift register (zero~7) to the host via the MISO signal line. At the identical time, the data dispatched with the aid of the host is acquired through the MOSI sign line, in order that the contents of the two shift registers are exchanged.

Conclusion
In this article I have written some of the basics of SPI communication protocol and I will continue this topic in my upcoming Articles Thank you..

Top comments (0)