嵌入式之总线协议:1、UART

嵌入式之总线协议:1、UART

目录
第一章 UART 帧格式讲解
第二章 UART 寄存器讲解
第三章 UART 编程
第四章 输出重定向
第五章 RS232、RS485协议原理与应用



前言

串口认知


一、UART简介

通用异步首发器(Universal Asynchronous Receiver Transmitter),是一种通用的串行 、异步通信总线,该总线有两条数据线,可以实现全双工的发送和接收。
在嵌入式系统中常用于主机和辅助设备之间的通信。

下面对关键概念进行解析:

1、串行/并行

communication
insert image description here

1.1 并行

并行通信时数据的各个位同时传送,可以字或字节为单位并行进行。并行通信速度快,但用的通信线多、成本高,故不宜进行远距离通信。
计算机或PLC各种内部总线就是以并行方式传送数据的。

insert image description here
总线在传递数据的时候传递的是高低电平的信号。
并行数据传输:

1.2 串行

UART:通用异步首发器(Universal Asynchronous Receiver Transmitter),是一种通用的串行、异步通信总线。
insert image description here

2、异步

基本过程;
数据发送和接收,不是同一个时钟;

3、单工和双工通信

3.1 单工通信

insert image description here

3.2 半双工

可以双向发送;但是不能同时双向发送数据;

half duplex

3.3 全双工

The Universal Asynchronous Receiver Transmitter is a general-purpose serial and asynchronous communication bus.
Send data in two directions, and can send at the same time.
full duplex

4. Baud rate

The baud rate is used to describe the communication speed during UART communication, unit: bps (bit per second), that is, the amount of bit data transmitted per second.
1 byte=8 bit;

2. UART frame format

Idle bit : the data line is high level when idle ;
start bit : a low level signal needs to be sent first during serial communication . Signals used to distinguish idle states.
Data bits : Data bits can be sent 5-8 bits, and the sending order is: first send the low bit, then send the high bit; (big and small end)
check bit : follow the parity check, that is, if the number of 1 is an even number, set it to 1, and set it to an odd number 0. The check digit is optional. According to the requirements, if the sending speed is required to be fast and the accuracy is not required, the check digit can be omitted; if the data accuracy is to be ensured, the check digit should be used. ;
Stop bit : indicates the end of a communication, the data line is high level , which can be 1 bit, 1.5 bit, or 2 bits;

insert image description here
Suppose there is a char type data:
char is defined as 8 bits: 0X55
converted to binary: 0101 0101

insert image description here
How to distinguish the above picture:
Baud rate: the number of binary bits transmitted per second;
determine a 0 or two 0s by pinching the time;
distinguish how many 0s and 1s are sent by counting the time, because the waves The baud rate specifies the communication speed; if the baud rate is 1bps, then it takes 1s to send 1 bit; if the time takes 2s, then 2 bits must be sent;

In order to avoid cumulative errors, it is stipulated that a maximum of 1 byte (byte) or 8 bits (bit) can be sent at one time.
Asynchronous communication:

3. Hardware connection

Cross connect:
insert image description here

4. UART controller

In general, the processor will integrate a UART controller, so that when using UART for communication, it only needs to set its internal related registers.
insert image description here

Guess you like

Origin blog.csdn.net/yechen1/article/details/128135790