3.S5PV210串口通信详解(一)

来源:互联网 发布:熊猫网络电视 编辑:程序博客网 时间:2024/06/06 01:04

串口全称: (UART:Universal Asynchronous Reciver And Transmitter)通用异步收发器,简称串口。

S5PV210的串口控制器工作原理框图:
整个串口控制器包括transmitter 和 receiver两部分。这两个部分的功能彼此独立,transmitter负责向外发送
信息,receiver负责从外接收信息。然后再包括一个波特率发生器。


DATA TRANSMISSION(数据发送):

The data frame for transmission is programmable. It consists of a start bit, five to eight data bits, an optional parity bit, and one to two stop bits, specified by the line control register (ULCONn). The transmitter can also produce a break condition that forces the serial output to logic 0 state for one frame transmission time. This block transmits the break signals after the present transmission word is transmitted completely. After the break signal transmission, the transmitter continuously transmits data to Tx FIFO (Tx holding register, in case of Non-FIFO mode)。

传输的数据帧是可被编程的。一帧数据包含一个开始位,5~8个有效数据位,1个可选的奇偶校验位和1~2个停止位,详细的可以通过 ULCONn 寄存器来控制。这个发送器也能产生一个中断条件,它可以强制在一个帧传输时间内让串口输出0。在当前传输字传输完成后,这个 传输块产生一个中断信号。中断信号传输之后,发送器继续传输数据给Tx FIFO(如果是Non-FIFO模式,数据给Tx holding寄存器)。


DATA RECEPTION(数据接收):

Similar to data transmission, the data frame for reception is also programmable. It consists of a start bit, five to eight data bits, an optional parity bit, and one to two stop bits in the line control register (ULCONn). The receiver detects overrun error, parity error, frame error and break condition, each of which sets an error flag.

* Overrun error indicates that new data has overwritten the old data before the old data was read.

* Parity error indicates that the receiver has detected an unexpected parity condition.

* Frame error indicates that the received data does not have a valid stop bit.

* Break condition indicates that the RxDn input is held in the logic 0 state for more than one frame transmission time.

Receive time-out condition occurs if no data is received during the 3-word time (this interval follows the setting of Word Length bit) and the Rx FIFO is not empty in the FIFO mode.

类似数据传送一样,接收数据帧也是可编程的。一帧数据包含一个开始位,5~8个有效数据位,1个可选的奇偶校验位和1~2个停止位,可以通过 ULCONn设置。接收器检测到溢出错误、奇偶校验错误、数据帧错误和中断条件,每一种情况都会设置一个相应的错误标志。

* 溢出错误:在旧的数据被读之前,新的数据覆盖了旧的数据。

* 奇偶校验错误: 接收方检测到了一个意想不到的奇偶校验位。

* 帧错误:接收到的数据没有一个有效的停止位。

* 中断条件: RxDn输入在逻辑0的状态多于一个帧传输时间。

如果在3个字时间内没有接收到数据(这个时间跟着字长的设置变化)和在FIFO模式下Rx FIFO是非空的时候会出现接收超时。


AUTO FLOW CONTROL (AFC)自动流控制简称流控:

The UART0 and UART1 in S5PV210 support auto flow control (AFC) using nRTS and nCTS signals. UART2 supports auto flow control if TxD3 and RxD3 are set as nRTS2 and nCTS2 by GPA1CON(GPIO SFR). In this case, it can be connected to external UARTs. To connect UART to a Modem, disable the AFC bit in UMCONn register and control the signal of nRTS using software.

In AFC, the nRTS signal depends on the condition of the receiver, whereas the nCTS signals control the operation of transmitter. The UART's transmitter transfers the data to FIFO if nCTS signals are activated (in AFC, nCTS signals means that other UART's FIFO is ready to receive data). Before UART receives data, the nRTS signals must be activated if its receive FIFO has more than 2-byte as spare. The nRTS signals must be inactivated if its receive FIFO has less than 1-byte as spare (in AFC, the nRTS signals means that its own receive FIFO is ready to receive data).

在S5PV210里UART0和UART1支持使用nRTS和nCTS信号的自动流控制(AFC)。如果TxD3和RxD3通过GPA1CON设置为nRTS2和nCTS2功能时UART2也支持自动流控制。在这种情况下,它能连接到外部的串口,通过串口连接一个调制解调器,通过UMCONn寄存器失能AFC位然后使用软件控制nRTS信号

在使用AFC时,nRTS信号取决于接收器的状态而nCTS信号控制操作发送器。如果nCTS信号被激活UART的发送器就会发送数据到FIFO(使用AFC时,nCTS表示其它串口的FIFO已经准备好了接收数据)。UART接收数据之前,如果它的接收接收FIFO区有超过两个字节空闲,nRTS信号被激活(即置位)。如果它的接收FIFO区少于一个字节空闲,nRTS信号必须被失能(即复位)(在AFC情况下,nRTS信号表示它自己的接收FIFO已经准备好了接收数据


通俗简单的说明一下AFC(自动流控制):

数据在两个串口之间进行传输时,常常会出现丢失数据的情况,比如两个串口之间的通讯速率不同,或者当接收端的接收缓冲区已经满的时候,这时发送方再继续发送数据就会造成数据丢失的情况。自动流控制的出现就是为了解决类似这种问题,比如结合上面的解释,有两个信号线nRTS和nCTS,当接收方接收缓冲区数据满时也就是上面说的接收方FIFO少于1个字节的空闲空间时,nRTS置0,这时发送方检测到后就会通过nCTS信号控制发送器不再发送数据,等检测到nRTS置位(即接收方FIFO能接收数据时),再通过nCTS控制发送方发送数据。

现在基本都不用流控:原因是现在设备间的通讯很少再使用串口,大部分都使用USB、以太网等进行通信,串口使用比较多的是调试程序时使用,一般程序调试没有对数据完整性有十分严密的要求,再加上由于现在硬件的发展已经完全能够协调串口间的发送和接收,因此流控一般在做硬件时一般都不会再接线使用了,所以我们一般使用时也不会使用流控功能。





原创粉丝点击