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
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.
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
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.
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.
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.
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.
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.
Figure 7. Stop bit
UART transmission steps
Step 1: The sending UART receives data in parallel from the data bus.
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.
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.
Figure 10. UART transmission
Step 4: The receiving UART discards the start bit, parity bit, and stop bit in the data frame.
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.
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.
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:
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- I made a website to download Keil, Cube and other resources. Does anyone want to try it? It's free and has no speed limit.
- Does leaving the charger plugged into the socket consume electricity?
- Choosing the Right RF Transceiver IC
- Let’s talk about understanding diode parameters. What key parameters do engineers need to know when designing?
- Common impedance matching methods
- Application of digital control system in smart home field
- Python surpasses Java to become the second most popular language on GitHub
- I have posted a post about 1588BS dot matrix before. This is the follow-up, which is about 51 single chip microcomputer.
- Lesson 1: Talking about IoT and 5G
- 8 dynamic parameters of digitizer