androidrs232串⼝协议,RS232串⼝协议详解 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 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 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 ha
ve 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的对⽐
600x22助燃剂要对⽐的项电子政务信息平台
所属类型
数据位个数
主要作⽤和功能
备注
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之前的数据流关系