Understanding UART Protocol Frame Format

Look at the image below; you probably guessed that today’s protagonist is UART. The serial port we commonly refer to includes both TTL level and RS-232 level, and in embedded systems, the serial port of microcontrollers is usually TTL level.

Understanding UART Protocol Frame Format

Today’s content is about the frame format of UART, which is quite simple; those who have worked with microcontrollers should be familiar with it.

UART stands for Universal Asynchronous Receiver/Transmitter, which means universal asynchronous transceiver.

UART has two data lines, TX and RX, allowing for full-duplex communication, meaning that both the transmitter and receiver can transmit data simultaneously on both links.

Understanding UART Protocol Frame Format

In contrast to full-duplex, there is also half-duplex communication. With only one data line, data transmission occurs as follows.

Understanding UART Protocol Frame Format

Or as shown below, at any given moment, only one link is transmitting data.

Understanding UART Protocol Frame Format

In addition to duplex modes, there is also simplex, where there is only a link from the transmitter to the receiver.

Understanding UART Protocol Frame Format

Having discussed the operating modes of UART, let’s move on to the main topic—UART frame format, which can also be referred to as the UART protocol. Communication between the microcontroller and PC must adhere to the UART protocol to ensure reliable data communication.

Understanding UART Protocol Frame Format

▲UART Data Frame Format

The meanings of each part are as follows:

  • Start Bit: Sends 1 bit of logic 0 (low level) to begin data transmission.

  • Data Bits: Can be 5 to 8 bits of data, sent low bit first, then high bit; commonly, 8 bits (1 byte) is used, with others like 7-bit ASCII code.

  • Parity Bit: Odd or even parity, adding the parity bit to the data bits so that the number of 1s is even (even parity) or odd (odd parity).

  • Stop Bit: The stop bit indicates the end of data transmission and can be 1/1.5/2 bits of logic 1 (high level).

  • Idle Bit: When idle, the data line is in a high level state, indicating no data transmission.

If we transmit data 0X33 (00110011), the corresponding waveform is as follows. Since LSB is sent first, the 8 bits of data are sent as 11001100.

Understanding UART Protocol Frame Format

▲Sending 0X33 Data Frame Format

If other data is sent, the process can be repeated in sequence.

UART is an asynchronous transmission, with 1 character as the transmission unit. The time interval between the transmission of two characters is unknown, for example, after transmitting 0X33, followed by 0X35, the time interval between these two is unknown.

However, the time interval between adjacent bits within the same character is fixed. For example, the time interval between the two low bits of 0X33 is fixed, which relates to the concept of UART transmission rate—baud rate.

The unit of baud rate is bps, which stands for bits per second, indicating the number of bits transmitted per second.

A baud rate of 9600 bps means that 9600 bits are transmitted per second, so the time to transmit 1 bit of data is 1/9600 = 104μs. A baud rate of 115200 bps means that the time to transmit 1 bit of data is 8μs.

So, how do two serial ports send and receive data?

Firstly, UART1 sends 0X33 at a baud rate of 9600, first placing a low level pulse of 104μs width (start bit) on the data line, followed by two consecutive high level pulses of 104μs width (2 bits of logic 1), and so on.

Secondly, UART2 receives 0X33 at a baud rate of 9600, confirming the data by counting the widths of these data pulses.

To ensure the accuracy of data transmission and reduce errors, generally, the baud rate difference between UART1 and UART2 should be less than 10%, and only 1 byte (8 bits) can be transmitted at a time, effectively reducing cumulative errors.
Source: Remember Cheng
Friendly Reminder:

Due to recent changes in WeChat public platform push rules, many readers have reported not seeing updated articles in time. According to the latest rules, it is recommended to click on “recommended reading, sharing, collecting,” etc., to become a regular reader.

Recommended Reading:

  • Counterattack! China will implement export controls on two rare metals

  • Xiaomi’s first electric car is reported to start at 149,900, with explosive cost-performance!

  • It is reported that Tesla’s Shanghai factory has laid off 50%, and all equipment has been dismantled!

Please click 【See】 to give the editor a thumbs up

Understanding UART Protocol Frame Format

Leave a Comment