
UART, or Universal Asynchronous Receiver/Transmitter, is one of the most commonly used communication protocols between devices. This article will explain the standard steps that should be followed when using UART as a hardware communication protocol.
When configured correctly, UART can work with many different types of serial protocols that involve sending and receiving serial data. In serial communication, data is transmitted one bit at a time over a single line or wire. In two-way communication, we use two wires for continuous serial data transmission. Depending on the application and system requirements, serial communication requires fewer circuits and wires, which can reduce implementation costs.
This article will discuss the basic principles of using UART, focusing on packet transmission, standard frame protocols, and custom frame protocols; custom frame protocols will be value-added features in terms of security compliance, especially during code development. Throughout the product development process, this document also aims to share some basic steps to check the actual use of datasheets.
Ultimately, the goal of this article is to help better understand and follow UART standards to maximize its capabilities and application advantages, especially when developing new products.
Communication protocols play an important role in organizing communication between devices. They are designed differently based on system requirements. Such protocols have specific rules that different devices must follow to achieve successful communication.
Embedded systems, microcontrollers, and computers mostly use UART as a form of hardware communication protocol between devices. Among the available communication protocols, UART’s transmitter and receiver only use two lines.
Although it is a widely used hardware communication method, it is not always fully optimized. When using the UART module internally in a microcontroller, the proper implementation of the frame protocol is often overlooked.
By definition, UART is a hardware communication protocol that uses asynchronous serial communication at a configurable speed. Asynchronous means there is no clock signal to synchronize the output bits entering the receiver from the transmitting device.
Interface
Figure 1. Two UARTs communicating directly with each other
The two signals for each UART device are named:
-
Transmitter (Tx)
-
Receiver (Rx)
The main role of the transmitter and receiver lines of each device is to send and receive serial data for serial communication.
Figure 2. UART with Data Bus
The transmitting UART connects to a control data bus that sends data in parallel form. Then, the data will be serially transmitted bit by bit over the transmission line (wire) to the receiving UART. Conversely, for the receiving device, the serial data will be converted back into parallel data.
The UART lines serve as the communication medium for sending and receiving data. Note that UART devices have dedicated pins for sending or receiving.
For UART and most serial communications, the transmitting and receiving devices need to set the baud rate to the same value. The baud rate refers to the rate at which information is transmitted to the channel. For serial ports, the set baud rate will be the maximum number of bits transmitted per second.
Table 1 summarizes a few key points about UART that must be understood.
Table 1. UART Overview
The UART interface does not use a clock signal to synchronize the transmitter and receiver devices, but instead transmits data asynchronously. The transmitter replaces the clock signal with a bit stream generated based on its clock signal, and the receiver samples the input data using its internal clock signal. The synchronization point is managed by the same baud rate between the two devices. If the baud rates are different, the timing of sending and receiving data may be affected, leading to inconsistencies in the data processing. The maximum allowed baud rate difference is 10%; exceeding this value can desynchronize the timing of the bits.
In UART, the transmission mode is in the form of packets. The mechanism connecting the transmitter and receiver includes the creation of serial data packets and the control of the physical hardware lines. A data packet consists of a start bit, data frame, parity bit, and stop bit.
Figure 3. UART Data Packet
Start Bit
When no data is being transmitted, the UART data transmission line usually remains at a high voltage level. To start data transmission, the transmitting UART pulls the transmission line from high to low and holds it for one clock cycle. When the receiving UART detects the high-to-low voltage transition, it begins to read the bits in the data frame at the frequency corresponding to the baud rate.
Figure 4. Start Bit
Data Frame
The data frame contains the actual data being transmitted. If a parity bit is used, the length of the data frame can be between 5 to 8 bits. If no parity bit is used, the length of the data frame can be 9 bits. In most cases, data is sent in a least significant bit (LSB) first manner.
Figure 5. Data Frame
Parity
Parity describes whether a number is even or odd. Through the parity bit, the receiving UART determines whether any data has changed during transmission. Electromagnetic radiation, inconsistent baud rates, or long-distance data transmission can all alter the data bits.
After the receiving UART reads the data frame, it counts the bits with a value of 1 and checks whether the total is even or odd. If the parity bit is 0 (even parity), then the total number of 1s or logical high bits in the data frame should be even. If the parity bit is 1 (odd parity), then the total number of 1s or logical high bits in the data frame should be odd.
When the parity bit matches the data, the UART considers the transmission error-free. However, if the parity bit is 0 and the sum is odd, or the parity bit is 1 and the sum is even, the UART considers that the bits in the data frame have changed.
Figure 6. Parity Bit
Stop Bit
To indicate the end of a data packet, the transmitting UART drives the data transmission line from low voltage to high voltage and holds it for 1 to 2 bit times.
Figure 7. Stop Bit
Step 1: The transmitting UART receives data in parallel from the data bus.
Figure 8. Data Bus to Transmitting UART
Step 2: The transmitting UART adds the start bit, parity bit, and stop bit to the data frame.
Figure 9. UART Data Frame on Tx Side
Step 3: From the start bit to the stop bit, the entire data packet is sent serially from the transmitting UART to the receiving UART. The receiving UART samples the data line at the pre-configured baud rate.
Figure 10. UART Transmission
Step 4: The receiving UART discards the start bit, parity bit, and stop bit from the data frame.
Figure 11. UART Data Frame on Rx Side
Step 5: The receiving UART converts the serial data back into parallel data and transmits it to the data bus of the receiving end.
Figure 12. Receiving UART to Data Bus
A key feature of UART is the implementation of frame protocols, which are not yet fully utilized. Their main use and importance is to provide value-added security and protection for each device.
For instance, when two devices use the same UART frame protocol, there is a possibility of connecting to the same UART without checking configurations, causing the devices to connect to different pins, which may lead to system failures.
On the other hand, implementing frame protocols ensures security as it requires parsing the received information based on the designed frame protocol. Each frame protocol is specifically designed to ensure uniqueness and security.
When designing a frame protocol, designers can set the expected headers and trailers (including CRC) for different devices. In Figure 13, 2 bytes are set as part of the header.
Figure 13. Example of UART Frame Protocol
According to the example, you can set unique headers, trailers, and CRC for your devices.
Header 1 (H1 = 0xAB) and Header 2 (H2 = 0xCD)
The header is the unique identifier that determines if you are communicating with the correct device.
Command (CMD) Selection
The command will depend on the list of commands used to create communication between the two devices.
Data Length (DL) for Each Command
The data length will depend on the selected command. You can maximize the data length based on the selected command, so it varies with the selection. In this case, the data length can be adjustable.
Data n (Variable Data)
The data is the payload to be transmitted from the device.
Trailer 1 (T1 = 0xE1) and Trailer 2 (T2 = 0xE2)
The trailer is data added after the transmission ends. Like the header, the trailer can also be a unique identifier.
Cyclic Redundancy Check (CRC Formula)
The cyclic redundancy check formula is an additional error detection mode used to detect whether the original data has changed unexpectedly. The CRC value of the sending device must always equal the CRC calculation value on the receiving end.
It is recommended to implement frame protocols for each UART device to enhance security. The frame protocol requires both the sending and receiving devices to use the same configuration.
When using any hardware communication protocol, it is essential to first check the datasheet and hardware reference manual.
Here are the steps to follow:
Step 1: Check the device’s datasheet interface.
Figure 14. Microcontroller Datasheet
Step 2: Check the UART address under memory mapping.
Figure 15. Microcontroller Memory Mapping
Step 3: Check specific information about the UART port, such as operating mode, data bit length, parity bit, and stop bit.
The example MCU provides a full-duplex UART port that is fully compatible with the standard PC UART. The UART port offers a simplified UART interface for connecting other peripherals or hosts, supporting full-duplex, DMA, and asynchronous serial data transmission. The UART port supports 5 to 8 data bits, with no, even, or odd parity. Frames are terminated with one or two stop bits.
Step 4: Check the details of UART operation, including baud rate calculations. The baud rate is configured using the following example formula. This formula varies with the microcontroller.
Example UART port details in the datasheet:
-
5 to 8 data bits
-
1, 2, or 1 ½ stop bits
-
No, even, or odd parity
-
Programmable oversampling rates of 4, 8, 16, 32
-
Baud rate = PCLK/((M + N/2048) × 2OSR + 2 × DIV
Where:
OSR (Oversampling Rate)
UART_LCR2.OSR = 0 to 3
DIV (Baud Rate Divider)
UART_DIV = 1 to 65535
M (DIVM Fractional Baud Rate M)
UART_FBR.DIVM = 1 to 3
N (DIVM Fractional Baud Rate M)
UART_FBR.DIVN = 0 to 2047
Step 5: For the baud rate, be sure to check the peripheral clock (PCLK) to be used. This example has 26 MHz PCLK and 16 MHz PCLK available. Note that OSR, DIV, DIVM, and DIVN vary with the device.
Table 2. Baud Rate Examples Based on 26 MHz PCLK
Table 3. Baud Rate Examples Based on 16 MHz PCLK
Step 6: The next part is to check the detailed registers of the UART configuration. Understand the parameters involved in calculating the baud rate, such as UART_LCR2, UART_DIV, and UART_FBR. Table 4 lists the specific registers involved.
Table 4. UART Register Descriptions
Step 7: Check the details under each register, input the values to calculate the baud rate, and then begin implementing UART.
When developing robust, quality-driven products, familiarity with the UART communication protocol is highly advantageous. Knowing how to send data using just two lines, as well as how to transmit entire data packets or payloads, will help ensure that data is sent and received accurately. UART is the most commonly used hardware communication protocol, and having relevant knowledge can provide design flexibility in future designs.
You can use UART for many applications, such as:
-
Debugging: It is important to catch system errors early during development. Adding UART allows messages to be captured from the system to help troubleshoot errors.
-
Manufacturing Functional Level Tracking: Logging is very important in manufacturing. Logs can determine functionality and alert operators to what is happening on the production line.
-
Customer Updates: Software updates are very important. Complete dynamic hardware and the supporting updated software are crucial for having a complete system.
-
Testing/Validation: Validating before a product leaves the manufacturing process helps provide customers with the highest quality products.

Wishing you a prosperous Year of the Ox!
The editor will randomly select 5 lucky winners from the video’s likes and fans to receive ADI lucky prizes.
