2.2. RS232和UART之间的对比

其实RS232和UART不是一个东西,是有区别的。下面就来解释RS232和UART的关系。

只不过在多数情况下,都把UART和RS232混在一起说,此时都是指的是串口的意思

UART==Universal Asynchronous Receiver Transmitter

UART,通用,指的是:其可以配置而支持多种不同协议

即,UART的输出是很多bit,这些bit最终可以组成RS232、RS422、RS485等其他协议。

The UART (universal asynchronous receiver transmitter) is the heart of the serial hardware. It is a chip or part of a chip with the purpose to convert between parallel data and serial data. RS-232 UARTs also typically add the necessary start/stop and parity bits when transmitting, and decode this information when receiving.

A UART typically operates entirely on computer logic voltage. Its serial data input/output voltage is the computer logic voltage, not the serial line voltage. They leave the actual line interface to a particular line driver / receiver. This line driver / receiver does not necessarily need to be an RS-232 line driver / receiver, but could e.g. also be an RS-422 differential driver / receiver. This, and the fact that baud rate, parity, number of stop bits, number of data bits are programmable is the reason why UARTs are called universal. The distinction between UART and line driver / receiver blurs if they are both placed in the same chip. Such chips are typically also sold under the label 'UART'. UARTs are called asynchronous, because they don't use a special clock signal to synchronize with the the remote side. Instead, they use the start/stop bits to identify the data bits in the serial stream. Thanks to the UART the rest of the hardware, as well as the software application can deal with normal bytes to hold the communication data. It is the job of the UART to chop a byte into a series of serial bits when sending, and to assemble series of bits into a byte when receiving. UARTs typically contain eight bit wide receiver and transmission buffers. Of which not all bits might be used if e.g. a 7 bit transmission is used. Received serial data is provided in parallel in the receiver buffer, to-be-send data is written in parallel to the transmission buffer. Depending on the UART the buffers might just have a depth of one byte, or a few bytes (in the range of 15 or 16 bytes). The less deep the buffers are, the more precise the communication with the CPU needs to be. E.g. if the receiver buffer just has a depth of one byte, and the data is not fetched fast enough, the next received data can overwrite the previously received data in the buffer, and the previously received data is lost.

Because of the fact that the timing on the serial interface is important, UARTs are typically connected to a baud rate generator, either an internal one in the UART chip, or an external one.

UART的作用:

为了CPU更省事,省力:

不需要每次把一堆的字节,慢慢的转化为一个个bit,然后一点点塞到(设置到)传输通道中,发送到对方

而只需要:

把要发的数据字节流放到一个缓存buffer中,然后告诉UART有数据了,接着UART负责把每个字节转换为单个的8个bit,一点点去发送

简单说就是:

UART是把串行的字节数据,转换为并行的比特位,然后再传输过去

总结起来就是:

表 2.1. Serial、RS232、UART的对比

要对比的项 所属类型 数据位个数 主要作用和功能 备注
Serial 软件概念   串行,概念上属于“时分复用”,数据是随着时间不同,慢慢的传送过去的,且大多数是以一个一个bit位的形式发送的。USART, UART, RS232, USB, SPI, I2C, TTL等等,都属于串行方面的协议或概念。  
UART 硬件设备,电子电路,物理上的模块 1 最常用的一种串行协议。处理串行接口之间的通信,只不过此串行接口,往往都是RS232接口而已。 由于每传输一个字节,都要通过自己的起始位的下降沿起去同步,因此才叫做异步通信。
RS232 电气接口规范 2 串口通信的协议,定义了,DCE和DTE之间的,电气方面的特性:硬件接口即引脚和其功能,信号时序和含义等 更严格的说法应该把RS232叫做EIA-232;对于远距离通信,5V不可靠,所以才会加大电压采用12V,即+12V表示0,-12V表示1

RS232和UART,以及对应的Line Driver/Receiver,CPU等等模块之间的数据流关系,可用下图表示:

图 2.1. RS232和UART之前的数据流关系

RS232和UART之前的数据流关系