1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
uartoverview.md 8.52 KB
一键复制 编辑 原始数据 按行查看 历史
NEEN 提交于 2021-03-12 17:59 . !197 Docs Update version 1.0.1

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

Capability

Function

Description

Obtaining and releasing device handles

UartOpen

Obtains the UART device handle.

UartClose

Releases a specified UART device handle.

Reading and writing data

UartRead

Reads data of a specified length from a UART device.

UartWrite

Writes data of a specified length into a UART device.

Obtaining and setting the baud rate

UartGetBaud

Obtains the UART baud rate.

UartSetBaud

Sets the UART baud rate.

Obtaining and setting device attributes

UartGetAttribute

Obtains the UART device attributes.

UartSetAttribute

Sets the UART device attributes.

Setting the transmission mode

UartSetTransMode

Sets the UART transmission mode.

NOTE: All functions provided in this document can be called only in kernel space.

1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助