【ARM】串行通信

异步通信

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

 


异步串行通信的特点可以概括如下

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

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

   3)因为一个字符中的比特们长度有限,所以需要的接收时钟和发送时钟只要相近就可以

   4)异步方式的特点简单地说就是:字符间异步,字符内部各位同步

 


异步串行方式的数据格式

   1)1位起始位,规定为低电平0

   2)5~8位数据位,即要传送的有效信息

   3)1位奇偶校验位

   4)1~2位停止位,规定为高电平1


同步串行

   所谓同步通信,是指数据传送是以数据块(一组字符)为单位,字符与字符之间、字符内部的位与位之间都同步。

 

同步串行通信的特点可以概括为

   1)以数据块为单位传送信息

   2)在一个数据块(信息帧)内,字符与字符间无间隔

   3)因为一次传输的数据块中包含的数据较多,所以接收时钟与发送时钟严格同步,通常要有同步时钟

 

同步串行方式的数据格式

   1)两个同步字符作为一个数据块(信息帧)的起始标志

   2)n个连续传送的数据

   3)两个字节循环冗余校验码(CRC)


例子

 1 #include "2410lib.h"
 2 
 3 void  uart0_test(void);
 4 
 5  
 6 
 7 int main(int argc,char **argv)
 8 
 9 {
10 
11    sys_init();
12 
13    uart_printf("
 Embest Arm S3CEB2410 Evaluation Board
");
14 
15 while(1)
16 
17    {
18 
19        uart0_test();
20 
21    }        
22 
23 }
24 
25 void uart0_test()
26 
27 {
28 
29 char cInput[256];
30 
31    UINT8T ucInNo=0;
32 
33 char c;
34 
35    uart_init(0,115200,0);
36 
37    uart_printf("
 UART0 Communication Test Example
");    
38 
39    uart_printf(" Please input words, then press Enter:
");
40 
41 while(1)
42 
43    {
44 
45        c=uart_getch();
46 
47        uart_printf("%c",c);
48 
49 if(c!='
')          //enter key
50 
51            cInput[ucInNo++]=c;
52 
53 else
54 
55        {
56 
57            cInput[ucInNo]='';
58 
59 break;
60 
61        }
62 
63    }
64 
65    delay(1000);    
66 
67    uart_printf("
 The words that you input are: 
 %s
",cInput);      
68 
69    uart_printf(" end.
");  
70 
71 }
View Code
原文地址:https://www.cnblogs.com/lcw/p/3159419.html