Embedded Learning Notes UART Communication Protocol

The UART (Universal Asynchronous Receiver/Transmitter) is a crucial chip that enables communication between a computer and serial devices. One important aspect of UART is its role as a data terminal equipment interface, allowing the computer to interact with modems or other serial devices that use an RS-232C interface. As part of this communication process, the UART offers several key functions: 1. It converts parallel data from the computer into a serial data stream for transmission. 2. It also converts incoming serial data from external devices into parallel bytes for internal use within the computer. 3. The UART adds a parity bit to the outgoing data stream and performs a parity check on the received data to ensure accuracy. 4. It includes start and stop bits in the transmitted data, while removing them from the received data to maintain synchronization. 5. It manages interrupt signals from input devices like keyboards and mice, which are also serial interfaces. 6. It handles the synchronization between the computer and external serial devices to ensure reliable communication. 7. The UART supports asynchronous serial communication, where each character is sent one bit at a time. This is illustrated in the diagram below.

Embedded Learning Notes UART Communication Protocol

Understanding the structure of the signal is essential. Here’s what each bit represents: - **Start Bit**: A logic "0" signal that marks the beginning of a data transmission. - **Data Bits**: These follow the start bit and typically consist of 4 to 8 bits, forming a single character. Usually, ASCII encoding is used, and the data is transmitted starting from the least significant bit. - **Parity Bit**: Added after the data bits to help detect errors. It ensures that the number of "1" bits is either even (even parity) or odd (odd parity). - **Stop Bit**: A logic "1" signal that marks the end of a character. It can be 1, 1.5, or 2 bits long. - **Idle Bit**: Represents the absence of data transfer, maintaining a high-level state when no data is being sent. **Baud Rate** refers to the speed of data transfer, measured in bits per second. For example, if a system sends 120 characters per second and each character is 10 bits long, the baud rate would be 120 × 10 = 1,200 baud. All these parameters—data bits, parity, baud rate—can be configured through the COM interface or by setting the corresponding bits in the UART register. Understanding the function of each register bit is essential for low-level programming and hardware control. To better grasp how UART works in practice, here's a simple program flow that demonstrates the transmission process:

Embedded Learning Notes UART Communication Protocol

In this example, the `uart_init` function is used to configure the UART settings. Let's take a closer look at how `uart_init` is implemented in the system:

Embedded Learning Notes UART Communication Protocol

The code defines three UART registers: UART0, UART1, and UART2. These registers are set using specific pin assignments such as `rUFCON`, `rUMCON`, `rULCON`, `rUCON`, and `rUBRDIV`. By configuring these registers, developers can customize the behavior of the UART according to their application needs.

All In One PC

all in one computers, all in one desktops,all in one computer, all in one desktop,aio pc

Guangdong Elieken Electronic Technology Co.,Ltd. , https://www.elieken.com

Posted on