UART串口通信协议

一.概述

1.1  Overview

UART(通用异步接收器-发送器)是最常用的设备到设备通信协议之一。一般是需要两根数据线(RX,TX)连接通信设备。UART通信设备有定义数据帧的组成格式,与SPI和IIC不同的是,UART没有组网或是多主从通信的能力。

1.UART的优点 

1.仅需两根线即可进行全双工数据传输(电源线除外)。

2.不需要时钟或任何其他定时信号。

3.奇偶校验位确保将基本错误检查集成到数据包帧中。

2.UART的缺点

1.帧中数据的大小是有限的。

2.与并行通信相比,数据传输速度较慢。

3.发送器和接收器必须统一传输规则,并且必须选择适当的波特率。

4.不支持多个主机或从机。

二.通信协议

2.1.Structure of Data Packet or Frame :

在UART串行通信中,数据是异步传输的,即在发送器和接收器之间不涉及时钟或其他定时信号。 UART使用一些特殊的位(称为开始和停止位)来代替时钟信号。Synchronisation Bits (Start and Stop bits).

2.2.Baud Rate:

发送UART和接收UART必须在波特率上达成一致,才能成功进行数据传输。 波特率以每秒比特数为单位。 一些标准波特率是4800 bps,9600 bps,19200 bps,115200 bps等。在这9600 bps中,最常用的波特率是其中之一。例如,对于9600波特系统,一位需要1 /(9600 bps)≈104.2 µs。系统实际上无法每秒传输9600位有意义的数据,因为开销位和一字节传输之间的延迟可能需要额外的时间。

 Back to Basics: The Universal Asynchronous Receiver/Transmitter (UART) - Technical Articles

2.3. Start Bit:

UART数据传输线通常在不传输数据时保持在高电平。 为了开始数据传输,发送端UART在一个时钟周期内将传输线从高电平拉低到低电平,标志着传输的开始。 当接收端UART检测到高电压到低电压转换时,它开始以波特率的频率读取数据帧中的位。

2.4. Data Frame

数据帧包含正在传输的实际数据。 如果使用奇偶校验位,则可以是五位,最多八位。 如果不使用奇偶校验位,则数据帧的长度可以为九位。 在大多数情况下,数据首先以LSB发送。

2.5.Parity

奇偶校验位是接收UART判断传输期间是否有数据错误的方式。串口校验分几种方式: 1.无校验(no parity) 2.奇校验(odd parity)传输的数据中(不包含校验位)有奇数个逻辑“1”,那么校验位为0,反之为1。 3.偶校验(even parity)传输的数据中(不包含校验位)有偶数个逻辑“1”,那么校验位为0,反之为1。 4.mark parity:校验位始终为‘1’ 5.space parity:校验位始终为‘0’

https://www.eefocus.com/analog-power/474338

 2.6 Stop Bits:

字符数据结束标志,可以是1位,1.5位,2位的高电平。 由于数据是在传输线上定时的,并且每一个设备有其自己的时钟,很可能在通信中两台设备间出现了小小的不同步。因此停止位不仅仅是表示传输的结束,并且提供计算机校正时钟同步的机会。适用于停止位的位数越多,不同时钟同步的容错性越好,但是数据传输率同时也越慢。

2.7 IDLE Bits:

处于逻辑“1”状态,表示没有数据传输。

2.8 signals :

The following signals are used to create a UART interface however not every design needs to use every signal. A # symbol is used to designate an active low signal ie active at logic 0.

2.1.1 RXD

The RXD signal of a UART is the signal receiving the data. This will be an input and is usually connected to the TXD line of the downstream device.

2.1.2 TXD

The TXD signal of a UART is the signal transmitting the data. This will be an output and is usually connected to the RXD line of the downstream device.

2.1.3 RTS#

The RTS# (Ready to Send) signal of a UART is used to indicate to the downstream device that the device is ready to receive data. This will be an output and is usually connected to the CTS# line of the downstream device.

2.1.4 CTS#

The CTS# (Clear to Send) signal of a UART is used by the downstream device to identify that it is OK to transmit data to the upstream device. This will be an input and is usually connected to the RTS# line of the upstream device.

2.1.5 DTR#

The DTR# (Data Terminal Ready) signal of a UART is often used for flow control in modems, but many serial interfaces do not use this signal. It is used to signal that the modem is ready to connect.

2.1.6 DSR#

The DSR# (Data Set Ready#) signal of a UART interface is mostly seen in modem applications otherwise the pin is frequently unused.

2.1.7 DCD#

The DCD# (Device Carrier Detect) signal of a UART interface is mostly seen in modem applications otherwise the pin is frequently unused. It is used to indicate a connection is established.

三.电气规范

UART、RS232、RS485 在串口通信中,主要区别是电平的不同,其中 UART 通常使用 TTL 电平,下面介绍这几个存在的差异; TTL 全名是晶体管 - 晶体管逻辑集成电路(Transistor-Transistor Logic) RS232 逻辑 1 电平(MARK)=-3V~-15V,逻辑 0 电平(SPACE)=+3~+15V; 对于传输数据0x55,即二进制的01010101,RS232 和 TTL 的区别如下;

 https://www.eefocus.com/analog-power/474338

1.电压标准

UART 通常使用 TTL 电平。具体的电压等级需要参考MCU的数据手册和目标的数据手册。

TTL与CMOS电压标准

电平标准

子标准

VOH

VOL

VIH

VIL

TTL(Transistor-Transistor Logic)

LVTTL(Low Voltage TTL)

5V

>=2.4

<=0.5

>=2.0

<=0.8

3.3V

>=2.4

<=0.4

>=2.0

<=0.8

2.5V

>=2.0

<=0.2

>=1.7

<=0.7

CMOS(Complementary Metal Oxide Semiconductor)

LVCMOS (Low Voltage CMOS)

5V

>=4.45

<=0.5

>=3.5

<=1.5

3.3V

>=3.2

<=0.1

>=2.0

<=0.7

2.5V

>=2.0

<=0.1

>=1.7

<=0.7

2.IO 配置

TX:

UART数据传输线通常在不传输数据时保持在高电平。且在UART的传输过程中没有线与等操作,故UART的端口可以配置为推挽(Push-pull)或是开漏(Open-drain)加上拉电阻。

RX:

RX可以配置为浮空输入。

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值