Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

Click the Blue Word

Follow Us
UART (Universal Asynchronous Receiver/Transmitter) is a widely used serial communication protocol, typically used for communication between computers and peripherals. It is a general-purpose serial, asynchronous communication bus with two data lines that enable full-duplex transmission and reception. UART is a serial communication protocol that transmits data bytes bit by bit. UART transmission does not require a clock signal; instead, it uses start and stop bits to indicate the beginning and end of a data frame, hence the term “asynchronous” communication.

Communication Basics—Parallel and Serial

Parallel Communication

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

For example, sending 0x55 data, converted to binary as 01010101, can be transmitted simultaneously over eight parallel data lines.
Serial Communication

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

Unlike parallel communication, serial communication uses only one data line, requiring the transmission of eight bits of data sequentially.
Parallel and serial communication are two different data transmission methods, each with its own unique advantages and disadvantages. Below is a detailed comparison:
Advantages and Disadvantages of Parallel Communication
Characteristics:
Parallel communication transmits multiple bits of data simultaneously, with each bit using an independent transmission line. Common parallel interfaces include PCI, ATA (Parallel ATA), and parallel printer interfaces (LPT).
Advantages:
  1. High-Speed Transmission: Because multiple bits can be transmitted simultaneously, parallel communication can theoretically be faster than serial communication.
  2. Low Latency: Due to the simultaneous transmission of multiple bits, the latency is lower, making it suitable for applications that require quick responses.
Disadvantages:
  1. Signal Interference: When there are many data lines, electromagnetic interference (crosstalk) between the lines can lead to a decrease in signal quality, especially at high frequencies.
  2. High Cost: Multiple data lines are required, and each line must be precisely matched in length to prevent signal misalignment, making wiring complex and costly.
  3. Distance Limitations: Because multiple lines must maintain synchronization, signals can easily distort over longer distances, so parallel communication is usually limited to short-distance applications.
Advantages and Disadvantages of Serial Communication
Characteristics:
Serial communication transmits data sequentially, typically requiring only a pair of transmission lines (one for simplex).
Advantages:
  1. Simplified Wiring: Only a pair of transmission lines is needed, reducing wiring complexity and lowering design and manufacturing costs.
  2. Strong Anti-Interference Capability: Because there is only a pair of signal lines, there is little crosstalk between lines, making it suitable for long-distance transmission. Differential signal serial communication (such as RS-485, CAN) has even greater anti-interference capabilities.
  3. Good Data Synchronization: Serial communication often includes a clock signal (like SPI, I2C) or has its own synchronization mechanism to ensure complete data transmission.
Disadvantages:
  1. Relatively Low Transmission Rate: Since data is transmitted bit by bit, the bit rate is usually lower than that of parallel communication. However, modern high-speed serial communications (like USB 3.0, PCIe, SATA) have improved speed through higher clock frequencies and encoding techniques.
  2. Higher Latency: Because of bit-by-bit transmission, compared to parallel communication, it may introduce higher latency, especially when handling large data volumes.

Communication Basics—Simplex and Duplex

Simplex Communication

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

In simplex communication, there are two parties, distinguished as transmitter and receiver, and data can only be transmitted from the transmitter to the receiver, such as in the case of a radio that can only receive.
Duplex Communication

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

Half-Duplex:
Half-duplex communication allows data to be transmitted in both directions, but only one direction at a time. In other words, both parties can take turns sending and receiving data but cannot do so simultaneously. For example, in a walkie-talkie, only one person can transmit data at a time.
Full-Duplex:
Full-duplex communication allows data to be transmitted simultaneously in both directions. Sending and receiving can occur at the same time, allowing both parties to send and receive data without interfering with each other. For instance, a mobile phone can communicate bidirectionally.

Communication Basics—Baud Rate

Baud rate is a key parameter in communication systems, indicating the number of symbols transmitted per second or the number of changes in the modulation signal. It is commonly used to describe the data transmission rate in serial communication.
In serial communication, such as UART, RS-232, SPI, etc., the unit of baud rate is bps (bits per second), meaning the number of bits transmitted per second. The baud rate determines the speed of data transmission. For example, a baud rate of 9600 in UART communication means that 9600 bits can be transmitted per second.
Common baud rates used in serial communication include:
  • 9600

  • 19200

  • 38400

  • 57600

  • 115200

  • 230400

  • 460800

UART Frame Format

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols
  • Start Bit: Sends 1 bit logic 0 (low level) to begin data transmission.
  • Data Bits: Can be 5 to 8 bits of data, sending the low bit first and then the high bit, generally, 8 bits (1 byte) is common, with other examples including 7-bit ASCII code.
  • Parity Bit: Odd/even parity, with the number of 1s being even (even parity) or odd (odd parity).
  • Stop Bit: The stop bit marks the end of data transmission and can be 1/1.5/2 bits of logic 1 (high level).
  • Idle Bit: The data line remains high when idle, indicating no data transmission.
If transmitting data 0X33 (00110011), the corresponding waveform would look like this, with LSB first, so the 8 bits of data are transmitted as 11001100 sequentially.
Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

Problems with UART

Non-Uniform Electrical Interfaces
In different devices or systems, the electrical characteristics of the UART interface may vary. The main reason is that UART does not strictly specify the electrical standards it uses, leading to potential incompatibility when connecting different devices. Specific manifestations include:
1. Voltage Level Differences: The signal levels of UART may differ across devices, for example:
  • RS-232 standard voltage range is typically between -12V and +12V.
  • TTL (Transistor-Transistor Logic) UART typically uses 0V (low level) and 3.3V or 5V (high level).
  • Some embedded devices may even use 1.8V signal levels.
Directly connecting devices with different voltage standards may lead to communication failures or even damage to the devices.
2. Inconsistent Ground References: Different devices may have different definitions for electrical ground references, especially in long-distance communication, mismatched grounding can cause noise or interference.
3. Connector Differences: UART does not specify a unified connector type, so different devices may use different pin definitions and interface forms (such as DB9, DB25, IDC ribbon cables, etc.), leading to physical connection incompatibility.

RS232 Protocol

RS-232 protocol is a standard serial communication protocol, formally known as “Recommended Standard 232”, which defines how data is transmitted in serial data communication. RS-232 was widely used for communication between computers and peripherals (such as modems, printers, etc.), especially in the 1980s and 1990s. In embedded systems, RS-232 is still used in some low-speed, short-distance communication scenarios.
Main Features of RS-232 Protocol
1. Electrical Characteristics:
Signal voltage: RS-232 uses high voltage levels to represent logical states. The standard specifies:
  • Logic “1” (idle state, usually negative voltage) is between -3V and -15V.
  • Logic “0” (active state, usually positive voltage) is between +3V and +15V.
RS-232 has a wide voltage range, thus providing good anti-interference capabilities, but it is not directly compatible with modern low-voltage logic circuits (like TTL levels), requiring level shifting.
Level Shifting: Typically, external circuits are added to the processor to shift the signal levels. For example, the MAX232 chip.

Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols

2. Signal Direction and Functions:

Full-duplex communication: RS-232 supports full-duplex communication, meaning that data can be sent and received simultaneously.
Single-ended signal transmission: Signals are transmitted over a single line (with a common ground), unlike protocols like RS-485 that use differential signals.
Common signal lines include:
  • TXD (Transmit Data): Sending data line.
  • RXD (Receive Data): Receiving data line.
  • RTS (Request to Send): Request to send.
  • CTS (Clear to Send): Clear to send (handshake signal).
  • DTR (Data Terminal Ready): Data terminal ready.
  • DSR (Data Set Ready): Data set ready.
  • GND (Ground): Ground signal.
3. Transmission Method:
  • Asynchronous communication: RS-232 uses asynchronous communication, meaning no additional clock signal is needed to synchronize the transmission between the sender and receiver, using start bits, data bits, and stop bits to mark the beginning and end of data frames.
  • Baud rate: Defines the number of bits transmitted per second. Common baud rates include 9600, 19200, 38400, 115200 bps, etc.
4. Connector Types:
The most common connector types are DB9 and DB25. These numbers indicate the number of pins on the connector.
In standard DB9 pinouts, commonly used pins include:
  • Pin 2: RXD
  • Pin 3: TXD
  • Pin 5: GND
5. Communication Distance and Rate:
  • Typically, RS-232 is suitable for short-distance communication (generally less than 15 meters) because the voltage signals decrease as distance increases.
  • Transmission rates are generally below 20 kbps.
6. Frame Structure:
  • Start Bit: 1 bit, marking the start of the data frame, usually low level (logic 0).
  • Data Bits:: 5-9 bits, representing the actual data being transmitted.
  • Parity Bit (optional): 1 bit used for error detection.
  • Stop Bit: 1-2 bits, marking the end of the data frame, usually high level (logic 1).
Currently, the most commonly used lines are RX, TX, and GND.
Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols
Common Applications of RS-232
  1. Computer Serial Port Communication: Early personal computers typically had RS-232 interfaces for connecting modems, mice, printers, and other peripherals.
  2. Embedded Systems: In some embedded systems and industrial control, RS-232 is used for low-speed, short-distance communication.
  3. Debugging Interface: As a simple and easy-to-implement communication protocol, RS-232 is commonly used for debugging and firmware updates in embedded systems.

Problems with RS-232

Despite its widespread use in early serial communication, RS-232 has gradually revealed some problems and limitations, especially under modern communication demands. Below are the main issues with RS-232:
1. Limited Transmission Distance
  • RS-232’s transmission distance is typically no more than 15 meters. As distance increases, the voltage signals gradually attenuate, leading to unstable or lost data transmissions.
  • In long-distance transmissions, signals may be interfered with or generate errors, making it unsuitable for remote communication scenarios.
2. Low Transmission Rate
  • RS-232 has a low transmission rate, typically below 20 kbps, with a maximum support of 115.2 kbps. Compared to modern interfaces like USB and Ethernet, RS-232 cannot meet high-bandwidth application needs.
  • For applications requiring high-speed data transmission (such as video and audio data), RS-232’s bandwidth limitations are particularly evident.
3. Single-ended Signal Transmission, Susceptible to Interference
  • RS-232 uses single-ended signal transmission, with signals transmitted over one line and the other serving as a ground reference. This method is easily affected by noise and electromagnetic interference, especially in industrial environments or long-distance transmissions.
  • In contrast, protocols like RS-485 use differential signal transmission, which has stronger anti-interference capabilities and is suitable for long-distance communication.
4. Non-Uniform Interfaces
  • RS-232 has multiple connector standards, such as DB9 and DB25, and the pin definitions may differ between devices. Therefore, special adapters or cables may be needed, increasing connection complexity.
  • Furthermore, due to the lack of a unified electrical interface standard, different devices may have inconsistent voltage levels (-12V to +12V), which can lead to communication failures or even damage when directly connected.
5. Point-to-Point Communication
  • RS-232 only supports point-to-point communication, meaning it can only connect two devices. This limitation makes it difficult to expand in multi-device communication scenarios.
  • Modern communication demands often involve network communication among multiple devices, while protocols like RS-485 can support multipoint communication.

RS-485 Protocol

RS-485 protocol is a serial communication standard commonly used in industrial communication, especially suitable for scenarios requiring long-distance, high-speed, and reliable data transmission. Fully known as “Recommended Standard 485”, RS-485 overcomes some limitations of RS-232, particularly in multipoint communication, anti-interference, and transmission distance.
Embedded Communication—Detailed Explanation of UART, RS232, and RS485 Protocols
Main Features of RS-485 Protocol
1. Differential Signal Transmission
  • RS-485 uses differential signal transmission, meaning data is transmitted through two signal lines (marked A and B), with the signal being the voltage difference between the two lines.
  • When the voltage on line A is higher than that on line B, it represents logic

Leave a Comment