← Back to list

UART, RS232, RS485, I2C, SPI Protocols and Realization

This article introduce the most important communication protocols in modern electronics and embedded systems. Such as UART, RS232, RS485…

Ac Studio · 2024-10-25 12:05 · 3 claps · 6.0 min read
#uart #rs232 #rs485 #i2c #spi
Open on Medium ↗

UART, RS232, RS485, I2C, SPI Protocols and Realization

2024.10.01

2024.10.01

In modern electronic devices and embedded systems, various communication protocols play a crucial role. These protocols dictate how data is reliably and efficiently transferred, whether it’s for data exchange between devices or communication between sensors, microcontrollers, and computers. Among many communication protocols, UART, RS232, RS485, I2C, and SPI are the most common. These protocols specify the standards for the first (physical) and second (data link) layers of the OSI network model, covering aspects like the number of wires needed, voltage standards, and data framing and error checking. Understanding the basics, functionality, and applicable scenarios of these protocols helps engineers design, debug, and optimize systems more effectively, thus enhancing overall device performance and reliability.

UART

The Universal Asynchronous Receiver-Transmitter (UART) is a widely used communication protocol.

When transmitting data, there are two main methods: parallel and serial communication. Suppose there are 8 data points to be sent from device A to device B; the transmission can be illustrated as follows:

Figure (1): Parallel and serial transmission

Figure (1): Parallel and serial transmission

In other words, parallel communication involves multiple wires, allowing multiple data points to be transmitted simultaneously, while serial communication uses a single wire through which data is transmitted in sequence. UART is a type of serial communication.

Additionally, UART uses two wires to transmit data in a full-duplex mode, meaning one wire can transmit data from device A while the other wire receives data from device B simultaneously.

Figure (2): Full-duplex

Figure (2): Full-duplex

Note that the wiring is crossed because device A’s transmission wire needs to connect to device B’s receiving wire, and vice versa.

Next, let’s look at the UART frame format.

Figure (3): UART frame format

Figure (3): UART frame format

The image above shows the number of bits required for data transmission and their purposes. When there is no data to transmit, it remains at a high voltage level. To start data transmission, a low-voltage start bit is first sent, indicating to the receiver that transmission is beginning. After data transmission, a parity bit is sent to verify the data’s integrity. The sender and receiver agree on rules in advance, and the data is verified accordingly. Parity can be odd or even.

  • Even parity: Counts the number of bit 1s and ensures there is an even number. For example, if the data is 01000101, the parity bit would be 1 to make a total of 4 bits at 1 (even). If the receiver receives 4 bits at 1, it indicates that the data was transmitted correctly. If an odd number is received, a bit error is indicated (although it does not specify which bit).
  • Odd parity: Counts the number of bit 1s and ensures there is an odd number.

Of course, two-bit errors could occur, resulting in an even number of bits, and the error might go undetected. However, the likelihood of two-bit errors is much lower than that of single-bit errors. The probability that error occurs in the first eight bits is also higher than that at the last bit. Lastly, a high-voltage stop bit indicates the end of transmission. For example, if we’re transmitting 00010111, the voltage will look like the graph below.

Figure (4): Voltage of transmitted signal

Figure (4): Voltage of transmitted signal

If a long data stream is to be transmitted, it can be sent multiple times in this format.

RS232

UART defines the frame format, specifying the data format for transmission. Unlike UART, RS232 is a physical layer communication protocol often used in combination with UART. In RS232, voltages between -3V and -15V represent bit 1, and voltages between 3V and 15V represent bit 0. Today, RS232 usually uses DB-9 or DB-25 connectors.

Figure (5): DB-9 Source: D-subminiature wikipeida

Figure (5): DB-9 Source: D-subminiature wikipeida

In many cases, only three lines — TX (transmit), RX (receive), and GND (ground) — are used. Since RS232 uses separate wires to transmit and receive date, it supports full-duplex communication and has a transmission range of about 15 meters. RS232 supports only point-to-point communication between two devices.

RS485

RS485, unlike RS232, does not have a specific interface type. For improved interference resistance, RS485 uses differential signals to distinguish bit 0 from bit 1. In a differential signal, the voltage difference between two wires determines bit values.

RS485 supports two wiring configurations: two-wire half-duplex and four-wire full-duplex. In two-wire half-duplex, the wires can only transmit or receive at any given time, hence the term half-duplex. In four-wire full-duplex, two wires are used for transmitting, and two for receiving, enabling full-duplex communication. RS485 has a transmission range of up to 1200 meters and supports multipoint communication, allowing multiple devices on the same wire to exchange information.

I2C

I2C is a serial communication protocol primarily used for short-distance communication between integrated circuits (ICs). It uses two wires: the Serial Data Line (SDA) for data transmission and the Serial Clock Line (SCL) for synchronization. With only one data line (SDA), I2C is half-duplex, meaning data can only be transmitted or received at a time. The clock line (SCL) keeps the devices in sync and controls the data transfer rate.

I2C supports multiple devices on the same bus, organized into master and slave roles. A device can act as either master or slave, though only one master can communicate at a time, providing high flexibility for inter-device communication setups.

Figure (6): I2C

Figure (6): I2C

The master first sends a start signal, occupying the bus. Next, it sends a byte, where the first seven bits indicate the slave address. Each device can see the master’s signal and determines if it is the intended recipient. The transmission ends when the master sends a stop signal, after which both SDA and SCL return to a high-voltage state.

The voltage transitions on SDA and SCL indicate the start and stop signals:

  • Start signal: SDA goes from high to low voltage, with SCL at high.
  • Stop signal: SDA goes from low to high voltage, with SCL at high.

Figure (7): Start condition and end condition

Figure (7): Start condition and end condition

SPI

SPI (Serial Peripheral Interface Bus) is a high-speed, full-duplex serial communication protocol. Like I2C, SPI has master and slave roles. SPI typically requires four lines: MOSI, MISO, CS, and SCLK. MOSI (Master Output Slave Input) sends data from the master to the slave, while MISO (Master Input Slave Output) sends data from the slave to the master, enabling full-duplex communication. CS (Chip Select) addresses the target slave device.

SPI has four operating modes, controlled by CPOL (Clock Polarity) and CPHA (Clock Phase). CPOL determines whether SCLK remains at a high or low voltage during idle. If CPOL=0, SCLK remains low when idle; if CPOL=1, SCLK remains high during idle, as shown below.

Figure (8): CPOL

Figure (8): CPOL

When CPOL=0, the first edge of the SCLK signal is a rising edge (from low to high), and the second edge is a falling edge (from high to low).

CPHA determines whether the signal is sampled on the first or second clock edge. If CPHA=0, the signal is sampled on the first edge of each cycle. If CPHA=1, sampling occurs on the second edge of each cycle. For example, with CPOL=0:

Figure (9): CPHA

Figure (9): CPHA

Through an in-depth understanding of UART, RS232, RS485, I2C, and SPI protocols, engineers can select the most suitable communication method for a specific application to ensure system stability and efficiency. The appropriate protocol depends on the use case. For instance, I2C is simple and low-cost but slower than SPI, making it suitable for sensors, while SPI’s high speed is ideal for devices requiring real-time updates, like displays. This article aims to provide readers with a clearer understanding of these communication protocols.

[embed]Welcome to Ac Studio! Read This First Hi there! We’ve built a knowledge map to help you explore our content with ease.medium.com


메타데이터
post_id
776f080c9001
slug
uart-rs232-rs485-i2c-spi-protocols-and-realization-776f080c9001
url
https://medium.com/@acamvproducingstudio/uart-rs232-rs485-i2c-spi-protocols-and-realization-776f080c9001
canonical_url
https://medium.com/@acamvproducingstudio/uart-rs232-rs485-i2c-spi-protocols-and-realization-776f080c9001
author_url
https://medium.com/@acamvproducingstudio
status
ok
fetched_at
2026-07-22 10:16:32