UART

摘要:
帧是UART通信中最基本的单元,主要包括:起始位、数据位、校验位和停止位。

UART(Universal Asynchronous Receiver/Transmitter,通用异步收/发器)

s3c2440A 提供了三个UART端口,它们都可以通过查询、中断和DMA方式传输数据,而且每个UART都分别有一个64个字节的接收FIFO和一个64个字节的发送FIFO。

OVERVIEW


The UART can generate an interrupt or a DMA request to transfer data between CPU and the UART. The UART can support bit rates up to 115.2K bps using system clock. If an external device provides the UART with UEXTCLK, then the UART can operate at higher speed.
The S3C2440A UART includes programmable baud rates, infrared (IR) transmit/receive, one or two stop bit insertion, 5-bit, 6-bit, 7-bit or 8-bit data width and parity checking(奇偶校验).
Each UART contains a baud-rate generator, transmitter, receiver and a control unit.The transmitter and the receiver contain 64-byte FIFOs and data shifters. Data is written to FIFO and then copied to the transmit shifter before being transmitted. The data is then shifted out by the transmit data pin (TxDn). Meanwhile, received data is shifted from the receive data pin (RxDn), and then copied to FIFO from the shifter.
FEATURES
— RxD0, TxD0, RxD1, TxD1, RxD2, and TxD2 with DMA-based or interrupt-based operation
— UART Ch 0, 1, and 2 with IrDA 1.0 & 64-byte FIFO
— UART Ch 0 and 1 with nRTS0, nCTS0, nRTS1, and nCTS1(UART2 没有 nRTS、nCTS,所以它不支持 AFC)
— Supports handshake transmit/receive

UART 数据帧


UART是串行异步通信方式,通信过程中每次只能传输一位(1 bit),若干位组成一个数据帧(frame)。帧是 UART 通信中最基本单元,它主要包含:开始位、数据位、校验位(不是必须的)、停止位。

Data Transmission
The data frame for transmission is programmable. It consists of a start bit, 5 to 8 data bits, an optional parity bit and 1 to 2 stop bits, which can be specified by the line control register (ULCONn). The transmitter can also produce the break condition(中止条件), which forces the serial output to logic 0 state for one frame transmission time(相当于产生一个内容为零的数据帧). This block transmits
break signals after the present transmission word is transmitted completely. After the break signal transmission, it continuously transmits data into the Tx FIFO (Tx holding(保持/持有) register in the case of Non-FIFO mode).
Data Reception
Like the transmission, the data frame for reception is also programmable. It consists of a start bit, 5 to 8 data bits, an optional parity bit and 1 to 2 stop bits in the line control register (ULCONn). The receiver can detect overrun error(溢出错误), parity error, frame error and break condition, each of which can set an error flag.
— The overrun error indicates that new data has overwritten the old data before the old data has been read.
— The parity error indicates that the receiver has detected an unexpected parity condition.
— The frame error indicates that the received data does not have a valid stop bit.
— The break condition indicates that the RxDn input is held in the logic 0 state for a duration longer than one frame transmission time.(RxDn 输入端口保持逻辑0持续长于一个数据帧的传输时间)
Receive time-out condition occurs when it does not receive any data 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.

Auto Flow Control (AFC)


The S3C2440A's UART 0 and UART 1 support auto flow control with nRTS and nCTS signals. In case, it can be connected to external UARTs. If users want to connect a UART to a Modem, disable auto flow control bit in UMCONn register and control the signal of nRTS by software. In AFC, nRTS depends on the condition of the receiver and nCTS signals control the operation of the transmitter. The
UART's transmitter transfers the data in FIFO only when nCTS signals are activated (in AFC, nCTS means that other UART's FIFO is ready to receive data). Before the UART receives data, nRTS has to be activated when its receive FIFO has a spare more than 32-byte and has to be inactivated when its receive FIFO has a spare under 32-byte (in AFC, nRTS means that its own receive FIFO is ready to receive data).

Baud-rate Generation


Each UART's baud-rate generator provides the serial clock for the transmitter and the receiver. The source clock for the baud-rate generator can be selected with the S3C2440A's internal system clock(PCLK、FLCK/n )or UEXTCLK. In other words, dividend(被除数) is selectable by setting Clock Selection of UCONn. The baud-rate clock is generated by dividing the source clock (PCLK, FCLK/n or UEXTCLK) by 16 and a 16-bit divisor specified in the UART baud-rate divisor register (UBRDIVn). The UBRDIVn can be determined by the following expression:
UBRDIVn = (int)( UART clock / ( buad rate x 16) ) –1 -------> baud_rate = (int)(UART_clock/((UBRDIVn + 1) * 16)) //这里的 +1 是为了防止分母为零
( UART clock: PCLK, FCLK/n or UEXTCLK )
Where, UBRDIVn should be from 1 to (216-1), but can be set 0 (bypass mode) only using the UEXTCLK which should be smaller than PCLK.
For example, if the baud-rate is 115200 bps and UART clock is 40 MHz, UBRDIVn is:
UBRDIVn = (int)(40000000 / (115200 x 16) ) -1 = (int)(21.7) -1 [round to the nearest whole number(四舍五入为一个整数)] = 22 -1 = 21
Baud-Rate Error Tolerance
UART Frame error should be less than 1.87%(3/160).
tUPCLK = (UBRDIVn + 1) x 16 x 1Frame / PCLK     tUPCLK: Real UART Clock
tUEXACT = 1Frame / baud-rate             tUEXACT: Ideal UART Clock 、、这里的 1frame 是指,一个数据帧的长度(以位计)
UART error = (tUPCLK – tUEXACT) / tUEXACT x 100%
NOTES
1. 1Frame = start bit + data bit + parity bit + stop bit.
2. In specific condition, we can support the UART baud rate up to 921.6K bps. For example, when PCLK is 60MHz, you can use 921.6K bps under UART error of 1.69%.

UART 特殊寄存器


( 1) UART 线性控制寄存器(ULCONn):R/W 用于规定数据帧的格式
( 2) UART 控制寄存器(UCONn)
( 3) UART FIFO 控制寄存器(UFCONn)
( 4) UART MODEM 控制寄存器(UMCONn) :R/W 串口 MODM控制寄存器,AFC 使能控制等
( 6) UART 错误状态寄存器(UERSTATn)
( 7) UART FIFO 状态寄存器(UFSTATn)
( 8) UART MODEM 状态寄存器(UMSTATn)
( 9) UART 发送缓存寄存器(UTXHn)      :W   串口发送缓存寄存器,用于表示发送的数据(只写,按字节方式)

  #defineUTXH0 (*(volatile unsignedchar *)0x50000020)
(10) UART 接收缓存寄存器(URXHn) :R    串口接收缓存寄存器,用于读取串口的数据(只读,按字节方式)

  #defineURXH0 (*(volatile unsigned char *)0x50000024)

( 5) UART 接收发送状态寄存器(UTRSTATn) :R   串口发送/接收状态寄存器,保存着相应通道的接收和发送状态
(11) UART 波特率除数寄存器(UBRDIVn):R/W 波特率除数寄存器


UART第1张

//要实现简单通信,只需使用串口的三个引脚:TXDn、RXDn、GND(接地,这里不用设置)

/* GPIO registers */ //GPH2,GPH3 used as TXD0,RXD0

#defineGPHCON (*(volatile unsigned long *) 0x56000070)

#defineGPHDAT (*(volatile unsigned long *) 0x56000074)

#defineGPHUP (*(volatile unsigned long *) 0x56000078)

#define nGPHCON 0xa0 //GPH2、GPH3 使用他们的复用功能,都设置为10 (1010,0000)

#define nGPHUP 0x0 //使能上拉电阻,以稳定电平信号,保障数据传输的正确。


http://wenku.baidu.com/view/c07dc8f90242a8956bece454.html

免责声明:文章转载自《UART》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇嵌入式iframe子页面与父页面js通信方式seaJs学习笔记之javascript的依赖问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Tomcat下载安装及常见问题解决办法

一、Tomcat的下载: 下载地址:http://tomcat.apache.org/ 下载Tomcat6.0(在左侧的Download下,考虑到稳定性现在企业大部分还在用Tomcat6.0) (1)这两种直接解压就可以使用,一般下载这一种(解压到你想放的文件夹下,可以直接更改解压后的文件名,文件夹命名最好是英文。) 32-bit Windows zip...

Linux内核结构体--kfifo 环状缓冲区

转载链接:http://blog.csdn.net/yusiguyuan/article/details/41985907 1、前言   最近项目中用到一个环形缓冲区(ring buffer),代码是由Linux内核的kfifo改过来的。缓冲区在文件系统中经常用到,通过缓冲区缓解cpu读写内存和读写磁盘的速度。例如一个进程A产生数据发给另外一个进程B,进程...

转载:win10 下安装Oracle 11g(问题:环境不满足最低要求)

安装oracle11g时遇到INS-13001环境不满足最低要求 在以管理员身份运行setup.exe之后,出现了:[INS-13001]环境不满足最低要求,通过网上搜索之后找到了解决途径 首先,打开你的解压后的database文件夹,找到stage,然后cvu,找到cvu_prereq.xml文件,用记事本打开,增添下面内容 <OPERATING_...

Intel Core Microarchitecture Pipeline

Intel微处理器近20年从Pentium发展到Skylake,得益于制作工艺上的巨大发展,处理器的性能得到了非常大的增强,功能模块增多,不过其指令处理pipeline的主干部分算不上有特别大的变化,更多的是为了提高指令的处理速度添加一些模块以及各模块的增强与优化。 本文会以Intel Core微处理器架构为例去了解Intel微处理器pipeline的各个...

X86/X64处理器体系结构及寻址模式

由8086/8088、x86、Pentium发展到core系列短短40多年间,处理器的时钟频率差点儿已接近极限。尽管如此,自从86年Intel推出386至今除了添加一些有关流媒体的指令如mmx/sse之外。其它新增的大多数指令都能够从最初的指令集中组合实现相同的功能,整个编程模型维持了约有20多年。 1. 处理器体系结构 1.1. 处理器简要结构 我们都...

解决pgpool启动报错 ifup[/sbin/ip] doesn't have setuid bit

1.问题出现: 在centos7启动pgpool服务器报错ifup[/sbin/ip] doesn't have setuid bit 2018-11-25 01:14:14: pid 38122: WARNING: checking setuid bit of if_up_cmd 2018-11-25 01:14:14: pid 38122: DET...