UART: Understanding the Universal Asynchronous Receiver/Transmitter Hardware Communication Protocol

Publisher:EE小广播Latest update time:2021-05-14 Source: EEWORLDAuthor: ADI公司 | Eric Peña,高级固件工程师 Mary Grace Legaspi,固Keywords:UART Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

summary


UART, or Universal Asynchronous Receiver/Transmitter, is one of the most commonly used protocols for inter-device communication. This article describes the standard steps that should be followed when using UART as a hardware communication protocol.


When properly configured, the UART can work with many different types of serial protocols that involve sending and receiving serial data. In serial communication, data is transmitted bit by bit over a single line or wire. In bidirectional communication, we use two wires for continuous serial data transmission. Depending on the application and system requirements, serial communication requires less circuitry and wires, which can reduce the cost of implementation.


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 a value-added feature in terms of security compliance, especially during code development. During product development, this document also aims to share some basic steps to check the actual use of the data sheet.


Ultimately, the goal of this article is to help better understand and adhere to the UART standard in order to maximize its capabilities and application benefits, especially when developing new products.


“The biggest problem with communication is that people assume it has been communicated.”


—George Bernard Shaw


Communication protocols play an important role in organizing the communication between devices. It is designed in different ways based on the system requirements. Such protocols have specific rules that are followed by different devices for 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 uses only two wires for both the transmit and receive ends. Although it is a widely used hardware communication method, it is not fully optimized all the time. The proper implementation of the frame protocol is often ignored when using the UART module inside a microcontroller. By definition, UART is a hardware communication protocol that uses asynchronous serial communication at a configurable speed. Asynchronous means that there is no clock signal to synchronize the output bits from the transmitting device into the receiving end.


interface

image.png

Figure 1. Two UARTs communicating directly with each other


The two signals of each UART device are named as:


  • Transmitter (Tx)

  • Receiver (Rx)


The main function of the transmitter and receiver lines of each device is to send and receive serial data for serial communication.


image.png

Figure 2. UART with data bus


The transmitting UART is connected to a control data bus that transmits data in parallel form. The data is then transmitted serially one bit at a time on the transmission line (wire) to the receiving UART. In turn, the serial data is converted to parallel data for the receiving device. The UART lines serve as a communication medium for sending and receiving data. Note that UART devices have dedicated transmit and receive pins for either sending or receiving. For UART and most serial communications, the sending 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 used as the maximum number of bits per second that can be transmitted.


Table 1 summarizes a few points you must know about UART.


Table 1. UART Summary


image.png


The UART interface does not use a clock signal to synchronize the transmitter and receiver devices, but transmits data asynchronously. The clock signal is replaced by a bit stream generated by the transmitter based on its clock signal, and the receiver samples the incoming data using its internal clock signal. The synchronization point is managed by the same baud rate for both devices. If the baud rates are different, the timing of the transmitted and received data may be affected, resulting in inconsistencies in the data processing process. The maximum allowed baud rate difference is 10%, exceeding this value, the timing of the bits will be out of sync.


Data Transfer


In UART, the transmission mode is in the form of data packets. The mechanism connecting the transmitter and the receiver includes the creation of serial data packets and the control of the physical hardware lines. The data packet consists of a start bit, a data frame, a parity bit, and a stop bit.


image.png

Figure 3. UART data packet


Start bit


When not transmitting data, the UART data transmission line is usually held at a high voltage level. To start data transmission, the transmitting UART pulls the transmission line from a high level to a low level and holds it for 1 clock cycle. When the receiving UART detects the high-to-low voltage transition, it begins reading the bits in the data frame at a frequency corresponding to the baud rate.


image.png

Figure 4. Start bit


Data Frame


The data frame contains the actual data being transmitted. If a parity bit is used, the data frame length can be 5 to 8 bits. If a parity bit is not used, the data frame length can be 9 bits. In most cases, data is sent least significant bit first.


image.png

Figure 5. Data frame


Parity


Parity describes whether a number is even or odd. The parity bit allows the receiving UART to determine if any data has changed during transmission. Electromagnetic radiation, inconsistent baud rates, or long-distance data transmission can change 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), the number of 1s or logic high bits in the data frame should add up to an even number. If the parity bit is 1 (odd parity), the number of 1s or logic high bits in the data frame should add up to an odd number. When the parity bit matches the data, the UART considers the transmission to be error-free. However, if the parity bit is 0 and the sum is odd, or if the parity bit is 1 and the sum is even, the UART considers that a bit in the data frame has changed.


image.png

Figure 6. Parity bit


Stop bits


To signal the end of a packet, the transmitting UART drives the data transmission line from a low voltage to a high voltage for 1 to 2 bit times.


image.png

Figure 7. Stop bit


UART transmission steps


Step 1: The sending UART receives data in parallel from the data bus.


image.png

Figure 8. Data bus to transmit UART


Step 2: The sending UART adds the start bit, parity bit, and stop bit to the data frame.


image.png

Figure 9. UART data frame on the Tx side


Step 3: From the start bit to the end 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 preconfigured baud rate.


image.png

Figure 10. UART transmission


Step 4: The receiving UART discards the start bit, parity bit, and stop bit in the data frame.


image.png

Figure 11. UART data frame on the Rx side


Step 5: The receiving UART converts the serial data back into parallel data and transmits it to the data bus on the receiving end.


image.png

Figure 12. Receive UART to Data Bus


Frame Protocol


A key feature of UART is the implementation of the frame protocol, which has not been fully utilized. Its main use and importance is to provide added value in terms of security and protection to each device. For example, when two devices use the same UART frame protocol, it is possible that when connected to the same UART without checking the configuration, the devices will be connected to different pins, which may cause system failure.


On the other hand, implementing a frame protocol ensures security because the received information needs to be parsed according to 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 header and trailer (including CRC) for different devices. In Figure 13, 2 bytes are set as part of the header.


image.png

Figure 13. UART frame protocol example


According to the example, you can set a unique header, trailer and CRC for your device.


Header 1 (H1 is 0xAB) and Header 2 (H2 is 0xCD)

The header is a unique identifier that determines whether you are communicating with the correct device.


Command (CMD) selection


The command will depend on the command list used to create communication between the two devices. The data length (DL) of each command

The data length will depend on the command selected. You can maximize the data length depending on the command selected, so it will vary with the selection. In this case, the data length can be adjusted.


Data n (variable data)


Data is the payload to be transferred from the device.


Trailer 1 (0xE1 for T1) and Trailer 2 (0xE2 for T2)

The trailer is data added after the transmission ends. Just 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 that detects if the original data has been accidentally changed. The CRC value of the sending device must always be equal to the CRC calculated value at the receiver end.


It is recommended to implement a frame protocol for each UART device to increase security. The frame protocol requires that the sending and receiving devices use the same configuration.


How UART works


When using any hardware communication protocol, you must first check the data sheet and the hardware reference manual. Here are the steps to follow:

[1] [2]
Keywords:UART Reference address:UART: Understanding the Universal Asynchronous Receiver/Transmitter Hardware Communication Protocol

Previous article:Silicon Labs Announces High-Reliability Isolation Collaboration with Teledyne e2v
Next article:Application of devicenet bus technology in the underlying control system of industrial sites

Recommended ReadingLatest update time:2024-11-16 11:37

Stm32f407DISCOVEY study uart serial port baud rate summary
I have been debugging Stm32f407DISCOVEY these days. Since there is no ready-made library function routine for the serial port, I used the routine on the Shenzhouwang development board to directly debug. As a result, the serial port output is always messy, 115200 baud rate; I tried to change it to 38400 and it can actu
[Microcontroller]
STM8 study notes ---uart1 serial port interrupt
Uart1 serial port send and receive interrupts. Target: When the serial port receives 1, LED1 lights up; when it receives 2, LED2 lights up; when other characters are received, LED1 and LED2 are turned off. Proceed as follows: 1. Write led.h and led.c files. 2. Write uart.h and uart.c files, where the serial po
[Microcontroller]
Lesson 011: Use of Jz2400 Serial Port (UART)
Section 001 Hardware Knowledge_UART Hardware Introduction 1. Hardware introduction of serial port  The full name of UART is Universal Asynchronous Receiver and Transmitter, which means asynchronous transmission and reception.  Serial ports are widely used in embedded systems. The main uses are: Print debugging inf
[Microcontroller]
Lesson 011: Use of Jz2400 Serial Port (UART)
S3C2440 UART driver code template (RealView MDK)
A good memory is worse than a bad pen. To facilitate code review and code reuse in the future, the S3C2440 UART driver code is posted here. The friendly MINI2440 development board is used, and the development environment is RealView MDK 4.22. It should be noted that in this code, the initialization of GPIO is complete
[Microcontroller]
Understanding of UART FIFO
   Necessity of FIFO. When performing UART communication, the interrupt method is simpler and more efficient than the polling method. However, if there is no transceiver FIFO, each data (5 to 8 bits) transmitted must be interrupted and processed once, and the efficiency is still not high. If there is a transceiver FIFO
[Microcontroller]
STM32F10x series UART interrupt exception debugging experience
Hardware environment: STM32F105RCT6 Software environment: FreeRTOSV8 Problem description: The interrupt method is used to receive data, and then a frame of data is placed in the message queue. Then a special task is used to retrieve and process data from the message queue. Jlink debugging and burning are both poss
[Microcontroller]
STM32F10x series UART interrupt exception debugging experience
s3c2440A development board UART summary and UART code details
I. Overview: The s3c2440A provides three independent asynchronous serial ports, each of which can operate in interrupt mode and DMA mode, that is, the UART can generate an interrupt or DMA request for data transfer between the CPU and the UART. Each serial UART has a 64-byte transmit FIFO and a 64-byte receive FIFO.
[Microcontroller]
S3C2440 UART2 is configured as CTS problem solved
By default, the Linux kernel sets the function of uart2 to nRTS1 and nTCTS1, and it is not used as a normal serial port. If we want to use uart2 as a serial port, we need to make the following modifications: The Linux 2.6 kernel sets the value of the GPHCON register to 0x16faaa, which means that GPH6 is set to nRTS1
[Microcontroller]
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号