Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the working principle, advantages, disadvantages and applications of SPI bus

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you the working principle, advantages and disadvantages and application of SPI bus, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

When connecting a microcontroller to a sensor, monitor, or other module, have you ever considered how to communicate between two devices? What on earth are they talking about? How can they understand each other?

Communication between electronic devices is like communication between human beings. Both parties need to speak the same language. In electronics, these languages are called communication protocols. Fortunately, when building most DIY electronics projects, we only need to know a few communication protocols. In this series of articles, we will discuss the basics of the three most common protocols: serial Peripheral Interface (SPI), Internal Integrated Circuit (I2C), and Universal Asynchronous receiver / transmitter (UART) driven communication.

First, we will start with some basic concepts about electronic communications, and then explain in detail how SPI works.

SPI,I2C and UART are much slower than protocols such as USB, Ethernet, Bluetooth and WiFi, but they are simpler and use fewer hardware and system resources. SPI,I2C and UART are very suitable for communication between microcontrollers and between microcontrollers and sensors, where there is no need to transmit large amounts of high-speed data.

Serial and parallel communication

Electronic devices communicate with each other by sending data bits through wires physically connected to each other, a bit like a letter in a letter, except for 26 letters (in the English alphabet), one bit is binary and can only be 1 or 0. Bits are transferred from one device to another through a rapid change in voltage. In the system with a working voltage of 5V, 0 bit communicates as a short pulse of 0V and 1 bit communicates through a short pulse of 5V.

Data bits can be transmitted in parallel or serial form. In parallel communication, data bits are sent at the same time, each over a separate line. The following figure shows the parallel transmission of the letter "C" in binary (01000011):

In serial communication, these bits are sent one by one over a single line. The following figure shows the serial transmission of the letter "C" in binary (01000011):

Brief introduction of SPI Communication

Many devices adopt the SPI general communication protocol. For example, the SD card module, the RFID card reader module and the 2.4GHz wireless transmitter / receiver all use SPI to communicate with the microcontroller.

One of the unique advantages of SPI is that it can transmit data continuously. Any number of bits can be sent or received in a continuous stream. With I2C and UART, data is sent in packets, limited to a specific number of digits. The start and stop conditions define the start and end of each packet, so the data is interrupted during transmission.

Devices that communicate through SPI are in a master-slave relationship. The master device is the control device (usually a microcontroller), while the slave device (usually a sensor, display, or memory chip) receives instructions from the autonomous device. The simplest SPI configuration is a single-host, single-slave system, but a single host can control multiple slaves (described in more detail below).

SPI is the abbreviation of Serial Peripheral Interface (Serial Peripheral Interface). It is a high-speed, full-duplex, synchronous communication bus, and occupies only four lines on the pin of the chip, which saves the pin of the chip and saves space for the layout of PCB.

(1) MISO- Master Input Slave Output, master device data input, slave device data output; (2) MOSI- Master Output Slave Input, master device data output, slave device data input; (3) SCLK-Serial Clock, clock signal generated by master device; (4) CS-Chip Select, slave device enable signal, controlled by master device. * in fact, the number of slave devices is limited by the load capacitance of the system and by the ability of the master device to switch precisely between voltage levels.

How SPI works

Clock

The clock signal will synchronize the data bit output of the autonomous device with the bit sampling of the slave device. One bit of data is transmitted in each clock cycle, so the speed of data transmission is determined by the frequency of the clock signal. Because the master device is configured and generates a clock signal, the SPI clock is always the clock of the master device.

Any communication protocol in which devices share clock signals is called synchronization. SPI is a synchronous communication protocol, and there are some asynchronous methods that do not use clock signals. For example, in UART communications, both parties are set to a preconfigured baud rate that determines the speed and time of data transmission.

The clock signal in SPI can be modified using clock polarity and clock phase attributes. These two properties work together to define when to output and when to sample them. The clock polarity can be set by the host to allow output and sampling at the rising or falling edges of the clock cycle. The clock phase can also be set by the host to output and sample on the first edge or the second edge of the clock cycle, whether rising or falling.

Select from Devic

The master device can select the slave device to call by setting the CS / SS line of the slave device to a low voltage level. In the idle non-transmission state, the slave selection line is maintained at a high voltage level. There may be multiple CS / SS pins on the host to allow multiple slaves to connect in parallel. If there is only one CS/SS pin, multiple slave devices can be connected to the master device through a daisy chain.

Multiple slave Devic

SPI can be set to operate with a single master device and a single slave device, or it can be set to control multiple slave devices through a single master device. There are two ways to connect multiple slave stations to the master station. If the host has more than one slave selection pin, the slave can be connected in parallel, as follows:

If only one slave pin is available, the slave device can be daisy-chained as follows:

MOSI and MISO

The host sends data to the slave serially through the Mosi line. The data sent by the master device on the MOSI pin is received from the device. Data sent from the master device to the slave device is usually sent first in the most significant bits.

The slave can also send data back to the host through a serial MISO line. Data sent from the slave device back to the master device is usually sent first in the least significant bits.

SPI data transfer steps

1. The host outputs clock signals:

two。 The master device switches the SS / CS pin to a low voltage state, thus activating the slave device:

3. The host sends data to the slave one bit at a time along the MOSI line. The slave reads these bits when they are received:

4. If a response is required, the slave station will return the data to the master station one bit at a time along the Miso line. The host reads the bits when it receives them:

Advantages and disadvantages of SPI

Using SPI has some advantages and disadvantages. If you choose between different communication protocols, you should know when to use SPI according to the requirements of the project:

Advantages

There are no start and stop bits, so data can be streamed continuously without interruption

There is no complex slave addressing system, such as I2C

Higher data transfer rate than I2C (almost twice as fast)

Separate MISO and Mosi lines, so you can send and receive data at the same time

Shortcoming

Use four wires (two for I2C and UART)

Unable to confirm that the data has been received successfully (I2C has performed this operation)

No error checking, such as parity bits in UART

Allow only a single host the above is how the SPI bus works, advantages and disadvantages and applications, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 227

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report