What are the differences between SPI, UART, and I2C and their respective features?

Source: Internet
Author: User
Tags sdo
Differences:
SPI: high-speed synchronous serial port. 3 ~ 4-line interface, independent and synchronous sending and receiving
UART: Universal asynchronous serial port. Bidirectional communication based on the standard baud rate is slow
I2C: A three-line serial transmission mode. The communication protocol and usage can be found on the Internet.

Bidirectional data transmission with three lines
Serial peripheral interface
UART: Universal asynchronous transceiver
UART is a chip used to control computers and serial devices. One thing to note is that it provides an interface to the RS-232C data terminal device so that the computer can communicate with the modem or other serial devices that use the RS-232C interface. As part of the interface, UART also provides the following functions:
Converts parallel data transmitted from within a computer to the output serial data stream. Converts serial data from outside the computer into bytes for devices that use parallel data inside the computer. Add the parity bit to the output serial data stream and perform the parity check on the data stream received from the outside. Add the start and stop mark to the output data stream and delete the start and stop mark from the received data stream. Handle the interrupt signal sent by the keyboard or mouse (the keyboard and mouse pass are also serial devices ). It can manage the synchronization between computers and external serial devices. Some of the more advanced uarts also provide the buffer for the input and output data. Now the newer UART is 16550, which can store 16 bytes of data in the buffer before the computer needs to process the data, generally, the UART is 8250. If you buy a built-in modem, the modem usually has a 16550 UART.
I2C: it can be used to replace standard parallel bus and connect various integrated circuits and functional modules. I2C is a multi-master bus, so any device can work as the master controller and control the bus. Each device on the bus has a unique address that can work as a transmitter or receiver based on the capabilities of the device. Multi-channel microcontroller can coexist on the same I2C bus.

More detailed differences:
The first difference is of course the name:
SPI (Serial Peripheral Interface: Serial Peripheral Interface );
I2C (inter ic bus: indicates the INTER-ic bus)
UART (Universal Asynchronous Receiver Transmitter: Universal Asynchronous transceiver)
Second, the difference lies in the electrical signal line:
The SPI bus consists of three signal lines: SCLK, SDO, and SDI ). The SPI bus allows multiple SPI devices to connect to each other. The SPI device that provides the SPI serial clock is the SPI host or Master, and other devices are the SPI Slave or Slave ). Full duplex communication can be achieved between the master and slave devices. When there are multiple slave devices, you can also add a select line from the device.
If you use a general IO port to simulate the SPI bus, you must have an output port (SDO), one input port (SDI), and the other port depends on the type of the implemented device, if you want to implement a Master/Slave Device, You need to input the output port. If you want to implement only the master device, you need to output the port. If you want to implement only the slave device, you only need to input the port.

I2C bus is a two-way, two-line (SCL, SDA), serial, multi-master interface standard, with bus arbitration mechanism, it is ideal for close-range and non-regular data communication between devices. In its protocol system, the device address of the target device is always included during data transmission. Therefore, devices can be networked.
If you use a general IO port to simulate I2C bus and implement bidirectional transmission, you need an input/output port (SDA) and an output port (SCL ). (Note: I2C data is rarely known, and the description here may be incomplete)

The UART bus is an asynchronous serial port. Therefore, the structure of the two synchronous serial ports is much more complicated than that of the first synchronous serial ports. Generally, it is generated by the baud rate generator (the baud rate is 16 times the Transmission baud rate) UART Receiver, UART transmitter, hardware consists of two wires, one for sending, one for receiving.
Obviously, if a universal IO port is used to simulate the UART bus, an input port and an output port are required.

Third, we can see from the second point that SPI and UART can achieve full duplex, but I2C is not;

Fourth, let's take a look at the opinions of the ox!
Wudanyu: less I2C lines. I think it is more powerful than UART and SPI, but it is more technically troublesome because I2C requires bidirectional IO support and the pull-up resistance is used, I think the anti-interference capability is weak. It is generally used for communication between chips on the same board, and rarely for long-distance communication. SPI implementation is simpler. UART requires a fixed baud rate, that is, the two-digit data interval must be equal, while SPI does not matter because it has a clock protocol.
Quickmouse: the speed of I2C is a little slower than that of SPI. The protocol is a little more complex than SPI, but the connections are also less than standard SPI.

SPI,I2C,UARTDifferences between three serial bus protocols

SPI (Serial Peripheral Interface: Serial Peripheral Interface)

I2C (inter ic bus)

UART (Universal Asynchronous Receiver Transmitter: Universal Asynchronous transceiver)

 

SPI

 

The SPI includes these distinctive features:

Master mode and slave mode

Bi-directional mode

Slave select output

Mode fault error flag with CPU interrupt capability

Double-buffered data register

Serial clock with programmable polarity and phase

Control of SPI operation during wait mode

 

SPI has two modes: Normal Mode and Bidirectional Mode, including the following lines:

 

 

SS Slave Select

SCK Serial Clock

MOSI Master Output, Slave Input

MISO Master Input, Slave Output

 

 

MOMI Master Output, Master Input

SISO Slave Input, Slave Output

 

Among them, the first four lines are used for Normal Mode, which is also commonly used for the Normal Mode of the four lines.

 

MOSI

This pin is used to transmit data out of the SPI module when it is configured as a Master and receive data

When it is configured as Slave.

MISO

This pin is used to transmit data out of the SPI module when it is configured as a Slave and receive data

When it is configured as Master.

SS

This pin is used to output the select signal from the SPI module to another peripheral with which a data

Transfer is to take place when its configured as a Masterand its used as an input to receive the slave select

Signal when the SPI is configured as Slave.

SCK

This pin is used to output the clock with respect to which the SPI transfers data or receive clock in case

Slave.

 

SPI is a protocol that allows a master device to start synchronous communication with the slave device to complete data exchange. That is, SPI is a well-defined communication method. The advantage of this communication mode is that the number of ports occupied is small. Generally, four ports are enough for basic communication. The transmission speed is also high. Generally, the main device must have an SPI controller (but it can be simulated) to communicate with the SPI-based chip.

The communication principle of SPI is very simple. It requires at least four lines. In fact, three lines can also be used. It is also common to all SPI-based devices, including SDI (data input), SDO (data output), SCK (hour clock), and CS (chip selection ). Among them, CS is to control whether the chip is selected, that is, only when the chip selection signal is a pre-defined enable signal (high potential or low potential), this chip operation is effective. This allows connecting multiple SPI devices on the same bus.

Next we will be responsible for three lines of communication. Communication is completed through data exchange. First, we need to know that SPI is a serial communication protocol, that is, data is transmitted by one digit. This is the original reason for the SCK clock line. SCK provides the clock pulse, while SDI and SDO transmit data based on the pulse. The data output passes through the SDO line. The data changes when the clock goes up or down and is read along the following bottom or up. The same principle applies to input when one data entry is complete. In this way, 8-bit data transmission can be completed after at least eight clock signal changes (the top and bottom ends are once.

Note that the SCK signal line is only controlled by the main device, and the signal line cannot be controlled by the slave device. Likewise, a SPI-based device must have at least one master device.

This transmission feature: This transmission method has an advantage. Unlike ordinary serial communication, ordinary serial communication transmits at least 8 bits of data at a time, the SPI allows one-bit data transmission and even pause. Because the SCK clock line is controlled by the master device, data is not collected or transmitted from the device when no clock jump occurs. That is to say, the master device can control the communication by controlling the SCK clock line.

SPI is also a Data Exchange Protocol: Because the SPI data input and output lines are independent, data input and output can be completed simultaneously.

Different SPI devices are implemented in different ways, mainly because the data is changed and the collection time is different. The acquisition along or down the clock signal has different definitions. For details, see related device documentation.

 

I2C

 

Only two bus lines are required: one serial data line (SDA) and one serial clock line (SCL ).

Each device connected to the bus can use a unique address and a simple host slave relationship software to set the address host as a host transmitter or host receiver.

It is a real multi-host bus. If two or more hosts initialize data transmission at the same time, they can prevent data corruption through conflict detection and arbitration.

Serial 8-bit bidirectional data transmission bit rate up to 100 kbit/s in standard mode up to 400 kbit/s in high speed mode up to 3.4 Mbit/s

The on-chip filter can filter the glitch wave on the bus data line to ensure data integrity.

The number of ICS connected to the same bus is limited only by the maximum capacity of the bus PF.

 

UART

 

The UART bus is an asynchronous serial port. Therefore, the structure of the two synchronous serial ports is much more complicated than that of the first synchronous serial ports. Generally, it is generated by the baud rate generator (the baud rate is 16 times the Transmission baud rate) UART Receiver, UART transmitter, hardware consists of two wires, one for sending, one for receiving.

Obviously, if a universal IO port is used to simulate the UART bus, an input port and an output port are required.

UART is commonly used to control the chips of computers and serial devices. One thing to note is that it provides an interface to the RS-232C data terminal device so that the computer can communicate with the modem or other serial devices that use the RS-232C interface.

Obviously, SPI and UART can achieve full duplex, but I2C does not work.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.