SPI Vs I2C Vs UART - What Are The Differences Between These Protocols
SPI Vs I2C Vs UART - What Are The Differences Between These Protocols
SPI Vs I2C Vs UART - What Are The Differences Between These Protocols
When creating a development board, there are protocols for relating with active
components. In this article, we will be comparing SPI vs I2C vs UART. These
hardware interfaces are commonly used in microcontroller development.
Table of Contents
What is SPI?
spi
The SPI means Serial Peripheral Interface. It is a protocol that features four
wire-based full-duplex communication. The SPI is one of the most common serial
protocols well-suited for faster data rates. It uses four wires which are:
The SPI interface makes use of the master-to-slave format to regulate several slave
devices with a master. Unlike UART that is asynchronous, SPI is synchronous. SPI
utilizes a built-in clock from the master. This helps to ensure the slave and master
devices are operating on the same frequency.
SPI has continued to take on several forms over the years. Speed is the greatest
evolution in SPI. This protocol is now used in applications featuring speeds greater
than 100MHz. SPI can send data in various formats like Quad, Dual, and Single I/O
SPI. Data transmissions can be faster if more I/O is being used.
SPI communicates in two different ways. Firstly, it selects every device with a CS
line. Each device needs a separate CS line. The second method involves daisy
chaining. Here, every device is connected to another via its data out to the data in line.
The number of SPI devices you can connect has no limit.
In the SPI, there is master and slave communication. The master always starts the
communication. During the communication, data shifts out from the master and then
shifts into the slave. SPI supports multi-slave communication.
SPI works in a different way. It makes use of separate lines for data. This protocol
features a higher bus range speed. The SPI is a synchronous serial data transfer
between the peripheral device and the CPU. This protocol is ideal when you need a
fast and reliable interface.
When working with this protocol you need to have the appropriate set of tools. The
inclusion of logic analyzers and oscilloscopes is helpful in the development process.
An oscilloscope is a great tool to use when designing the SPI bus.
Pros
Supports full-duplex
Utilizes a master’s clock. So, it doesn’t require precision oscillators in slaves
Faster data transmission rate
Features simple software implementation
Has no stop and start bits
Features no complex slave addressing system
Cons
There will be complex wiring when more than one slave is in communication
Utilizes four wires
Doesn’t acknowledge data receiving
Doesn’t check errors
It gives room for a single master
What is I2C?
I2C
I2C protocol is ideal for applications that require various parts. 12C can have several
masters and slaves. You will find I2C in consumer electronics and industrial
equipment. 12C can maintain a vivid communication pathway while linking up about
128 devices to the mainboard.
This protocol features two pins. These pins are the Serial Clock Line (SCL) pin and
the Serial Data Line (SDL) pin. The SDL transfers and receives data. Meanwhile, the
SCL functions as a clock. I2C is a protocol that offers support to slow devices. Here,
the master can transmit and receive data from the slave. The master controls the clock
bus. However, in some cases, slaves can suppress the clock signal.
In the I2C protocol, the master transmits a start bit from its SDA pin. After this, the
seven-bit address chooses the slave. After it receives the address and start bit, the
slave transmits an acknowledge bit to the master. The slave listens to the SDA and
SCL for any incoming transmissions.
The master will know if the connection makes it to the correct slave once it gets the
transmissions. Then, the master chooses which memory it wants to access from the
slave. It achieves this by sending eight bits that specify which register to use.
After the address has been received, the slave prepares the select register. This is done
before it sends another ‘acknowledge bit’ to the master. The master transmits the data
bit to the slave after choosing the specific slave. After sending the data, the slave
sends a final acknowledge bit to the master.
The relationship between the slave and master devices isn’t constant. The sending and
receiving of data depend on the direction of data transmission at the time. The master
must address the slave before it transmits data. It must also address the slave if it
wants to get data from the slave.
The host receives the information the slave has sent. Then, the receiver ends the
receiving process. The host generates the timing clock. It also terminates data transfer.
Also, it is important to link up the power supply via a pull-up resistor.
Pros
Features a low signal/pin count even with several devices on the bus.
Supports several masters.
Supports multi slave and multi-master communication.
Uses two wires to create communication among several devices.
It can adapt to the demands of different slave devices.
Cons
It becomes complicated when there are more master and slave devices
It has a slower speed
The interface is half-duplex
What is a UART?
UART
This hardware peripheral converts the outgoing and incoming data into the serial
binary stream. UART functions when an application doesn’t require high-speed data
transmission. This communication device features a single receiver/transmitter. It
needs a single wire for data transmission and another wire for receiving data.
With the help of an RS232-TTL converter, you can interface a URT with a personal
computer. This is because a UART and an Rs232 don’t need a clock for receiving and
transmitting data. The UART frame features a 1or 2 stop bits and 1 start bit for serial
data transfer.
The UART features two core components; the receiver and transmitter. The receiver
has a control logic, receiver shift register, and a receive hold register. The transmitter
features the control logic, transmit hold register, and transmit shift.
A UART can function between devices in three different ways. These include the
simplex, half-duplex, and full-duplex. In simplex, the transmission of data is in one
direction. The half-duplex transmits data in either direction. The full-duplex transmits
data in both directions simultaneously.
The data packet then transmits at the transmit data pin. Here, the receiving UART will
interpret the data packet as its receiving data pin. Data transmission continues until
data in the transmitting UART finishes.
For data transmission to occur, the receiver and the transmitter must agree with some
configurations. These are:
Start bit
Baud speed
Parity bit
Stop bit
Data length
UART requires no clocks. It includes stop and start bits being transferred to indicate
the beginning and end of a message. With this, the receiving UART will know when
bits should start and stop reading. The receiving UART identifies a start bit and reads
the bits at the BAUD rate. This rate is the data transmission speed and is always set
to 115,200.
Both the receiving and transmitting UARTs must operate at almost the same baud rate.
If the BAUD rate’s difference is above 10%, the bits’ timing may go off. This may
render the data useless. You must be certain that UARTs can transfer and receive data
from the same packet.
Pros
Cons
UART, SPI, and 12C are serial communication protocols. However, these serial
protocols are different in terms of how they operate. Here, we will be comparing the
difference between these three protocols.
Pin designations
For a UART, TxD and RxD are the pin designations. The TxD refers to transmit data
while the RxD is the receive data. The pin designations for SPI include MISO, SS,
SCLK, and MOSI. The MISO refers to Master Input and Slave Output. SS refers to
slave select and SCLK refers to a serial clock. MOSI refers to master output and a
slave output. The pin designations for I2C are serial data (SDA) and serial clock
(SCL).
Type of communication
Clock
UART doesn’t use a common clock signal. Here, both devices utilize their
independent clocks. In an SPI, there is only one common clock signal between the
slave and master devices. In I2C protocol, there is a common clock signal between
multiple slaves and multiple masters.
Software
Communication Protocol
In terms of protocol, the UART uses a stop bit and a start bit for 8 bits of data. I2C
uses stop and start bits. For 8 bits of data I2C uses ACK. This indicates if data has
been received.
Number of wires
UART features 1 wire while SPI features 4 wires. On the other hand, I2C features 2
wires.
Conclusion
SPI vs I2C vs UART has been discussed in this article. Each of these communication
protocols has its unique features. As a user, it is important you choose a protocol that
meets your project’s requirements. For instance, the SPI is an ideal choice if you want
the fastest protocol. Meanwhile, if you need to connect several devices, the I2C is the
best option.
Related Posts:
https://www.raypcb.com/spi-vs-i2c-vs-uart/