Serial communication protocol - based STM32 UART serial communication protocol of the UART (a) Explanation

 

UART - Universal Asynchronous Receiver / Transmitter - Universal Asynchronous Receiver Transmitter.

 A, UART Introduction

The UART is an asynchronous serial communication protocol,

Works by each character transmitted data bit by bit transmission, data can be converted to be transmitted between the serial communication and parallel communication, flexibility to full-duplex data exchange with external devices.

UART USART is an upgraded version that supports synchronous mode, use the same UART

Second, Concepts

------------------------------------ UART COM port USB serial port RS - 232 TTL ---- -----------------------------------------

 UART, the performance of the hardware serial transceiver logic circuits can be integrated as independent modular chip

 COM port, serial communication ports, sometimes also referred to as serial port, a connector structure, where different from USB "Universal Serial Bus" and hard "the SATA", the interface standards and norms serial bus standard is RS-232

           There are two common physical standard, D-9-pin plug, DuPont, and 4-pin header,

 

 

USB ports: Universal Serial Bus, and serial entirely different concept. Although it is a serial communicate, but communication timing and signal level USB and serial ports are completely different, and therefore nothing to do with the serial port. USB is a high-speed communication interface for connecting various PC peripherals, U disk, keyboard and mouse, a removable disk, of course, also includes a module "USB serial" of. (USB to serial module, USB interface is UART module)

TTL, RS232, RS485, etc. is a logical level of representation, see: A


 

Three, U the ART Rationale

 

   When transmitting data, the CPU writes data to the parallel UART, UART serial issued according to a certain format on a wire; when receiving a data signal on the other wire UART detected, the serial collected in a buffer, to the CPU UART obtain these data can be read.

  TxD - transmit data RxD - receive data Gnd - is used to provide both a reference level

  UART using standard TTL / CMOS logic levels to represent data, represents a high level, a low level of 0 ,. In order to enhance anti-interference ability data, increase the length of the transmission, typically TTL / COMS logic level to the RS-232 logic levels


 

  Data transmission process : to transmit a data byte 'A' Example

  

 

   The two sides agreed to the baud rate (occupied every time); Transfer Protocol provisions 

     1) normal data line is in the "empty closed" state (state 1)

   2) When the data to be transmitted, UART TxD data line changes state, the state becomes 0, and maintaining a time, so that after the receiver detects the start bit, and then waiting for the start time of 1.5 to a one the obtained data line state detecting transmitted data.

  3) UART can have a 5/6/7/8 bit data, state change data line of a sender transmits a data out LSB first

  4) If a check function, UART after sending the data, but also transmits a parity bit: odd parity, parity - check bits along with the data bits, the number of "1" belongs to the odd or even.

  5) The last stop bit, the data line restored to the "empty closed" state (state 1), the stop bit length of three ways: 1, 1.5, 2

The following figure 1-1 TTL / COMS logic level, the transmission waveform A

  

 

 FIG. 1-2 RS - 232 at the logic level, the waveform of the transmission data A

  For TTL / CMOS level, between xV to 5V, it is considered a logical 1, yV 0V to be a logic 0.

  For RS - 232 level, between -3 V to -12V, it is considered a logical 1, between + 3V to + 12V to logic 0.

  RS-232 level / height ratio TTL CMOS, can be transmitted longer distances, using more than in the industry.

在ARM芯片上的串口都是TTL电平的,通过板子或外接电平转换芯片,可以转成RS232标准的接口。如图2-1所示

 

 如今终端上的RS-232标准的接口越来越少,越多的是USB口,因也可以使用USB转串口芯片将TTL电平转为USB传输电平。


 

四、异步串行通信的特点

所谓异步通信,是指数据传送以字节为单位,字符与字符间的传送是完全异步的,位与位的传送基本是同步的。

特点:

  1)以字符为单位传送信息

  2)相邻两字符间的间隔任意长

  3)由于一个字符的波特位长度有限,所以需要接受时钟和发送时钟相近就可以

  4)字符间异步,字符内同步


 

 

五、基本结构

  图3-1   UART结构图

   ARM处理器中UART功能相似,都有独立的通道,每个通道都可工作于中断或DMA模式,即UART可以发出中断或DMA请求以便在UART、CPU间传输数据。具体的UART特性可参见不同芯片的芯片手册。以下以S3C2440芯片分析UART的使用过程。

  S3C2440  UART的FIFO深度为64字节。发送数据时,CPU先将数据写入发送FIFO中,然后UART自动将FIFO的数据复制到“发送移位器”中,发送移位器将数据一位一位地发送到TxDn数据线上(按照设定的格式,插入开始位,校验位和停止位)。接收数据时,“接收移位器”将RxDn数据线上的数据一位一位接收进来,然后复制到FIFO中,CPU即可从中读取数据。UART的结构如图3-1所示。


 

六、使用UART

 

 

参考文档:

嵌入式LINUX应用开发手册 —— 韦东山

基于STM32之UART串口通信协议(一)详解

串口、COM口、UART口, TTL、RS-232、RS-485区别详解

Guess you like

Origin www.cnblogs.com/y4247464/p/12295764.html