UART Overview
Introduction
-
The Universal Asynchronous Receiver/Transmitter (UART) is a universal serial data bus used for asynchronous communication. It enables bi-directional communication between devices in full-duplex mode.
-
UART is widely used to print information for debugging or to connect to various external modules such as GPS and Bluetooth.
-
A UART is connected to other modules through two wires (as shown in Figure 1) or four wires (as shown in Figure 2).
-
TX: TX pin of the transmitting UART. It is connected to the RX pin of the peer UART.
-
RX: RX pin of the receiving UART. It is connected to the TX pin of the peer UART.
-
RTS: Request to Send signal pin. It is connected to the CTS pin of the peer UART and is used to indicate whether the local UART is ready to receive data.
-
CTS: Clear to Send signal pin. It is connected to the RTS pin of the peer UART and is used to indicate whether the local UART is allowed to send data to the peer end.
Figure 1 2-wire UART communication
Figure 2 4-wire UART communication
-
-
The transmitting and receiving UARTs must ensure that they have the same settings on particular attributes such as the baud rate and data format (start bit, data bit, parity bit, and stop bit) before they start to communicate. During data transmission, a UART sends data to the peer end over the TX pin and receives data from the peer end over the RX pin. When the size of the buffer used by a UART for storing received data reaches the preset threshold, the RTS signal of the UART changes to 1 (data cannot be received), and the peer UART stops sending data to it because its CTS signal does not allow it to send data.
-
The UART interface defines a set of common functions for operating a UART port, including obtaining and releasing device handles, reading and writing data of a specified length, and obtaining and setting the baud rate, as well as the device attributes.
Available APIs
Table 1 APIs for the UART driver
NOTE: All functions provided in this document can be called only in kernel space.