博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【ARM】串口通信·FS2410·裸机UART
阅读量:5817 次
发布时间:2019-06-18

本文共 1916 字,大约阅读时间需要 6 分钟。

开发环境


   (1)硬件平台:FS2410

   (2)主机:Ubuntu 12.04



FS2410串口的原理图


串口UART寄存器配置


配置TXD0与RXD0(GPH2、GPH3)


设置波特率(UBRDIVn)


设置传输格式(ULCONn)


选择时钟源与中断方式(UCONn)


设置FIFO(UFCONn)


设置流控(UMCONn)


接收字符和发送字符(UTRSTATn)


源代码

 //uart.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "2410addr.h"
                                                                        
void 
putc
(
char 
ch)          
//发送字符
{
    
while
(!(rUTRSTAT0 & 0x2) );      
//判断发送缓冲区是否为空
                                                                        
    
rUTXH0 = ch;         
//发送字符
                                                                        
}
                                                                        
char 
getc
(
void
)      
//接收字符
{
    
while
(!(rUTRSTAT0 & 0x1));      
//判断接收缓冲区是否为空
                                                                                
    
return 
rURXH0;      
//返回接收的字符
}
                                                                        
void 
putstr(
char 
*str)     
//发送字符串
{
    
while
(*str != 
'\0'
)
    
{
        
if
(*str == 
'\n'
)
        
{
            
putc
(
'\n'
);
            
putc
(
'\r'
);
        
}
        
else
            
putc
(*str);
                                                                        
        
str++;
    
}
}
                                                                        
int 
main(
void
)
{
    
char 
ch;
    
char 
str[100];
    
int 
i = 0, j;
                                                                        
    
for
(j = 0; j < 100; j++)       
//清空字符串
        
str[j] = 
'\0'
;
                                                                        
    
rGPHCON = rGPHCON & ~(0xf << 4) | (0xa << 4);    
//配置RXD0、TXD0
    
rGPHUP = 0x0c;       
//设置上拉电阻
                                                                        
    
rUFCON0 = 0;      
//不用FIFO
    
rUMCON0 = 0;    
//不用流控
    
rULCON0 = 0x3;    
//8位数据,1个停止位,无校验,正常模式
    
rUCON0 = 0x5;     
//时钟源位PCLK, 中断方式为查询
                                                                        
    
rUBRDIV0 = ((
int
)(50000000 / 115200 / 16) - 1);     
//设置波特率为115200
                                                                        
    
putc
(
'\r'
);
    
putstr(
"hello mystery \n"
);
                                                                        
    
while
(1)
    
{
        
ch = 
getc
();      
//接收字符
                                                                        
        
putc
(ch);      
//发送字符
                                                                        
        
str[i++] = ch;
                                                                        
        
if
(ch == 
'\r'
)
        
{
            
i = 0;
            
putc
(
'\n'
);
            
putstr(
"mystery:"
);
            
putstr(str);
            
putstr(
"\n"
);
                                                                        
            
for
(j = 0; j < 100; j++)    
//清空字符串
                
str[j] = 
'\0'
;
        
}
    
}
                                                                        
    
return 
0;
}

//start.S

1
2
3
4
5
6
7
8
9
10
11
12
13
.text
.global _start
_start:
#define WATCHDOG 0x53000000
    
ldr r0, =WATCHDOG
    
mov r1, #0
    
str r1, [r0]
                                                             
    
ldr sp, =1024*4
    
bl main
                                                             
loop:
    
b loop

//Makefile

1
2
3
4
5
6
7
8
uart.bin: start.S uart.c
    
arm-linux-gcc -c start.S -o start.o
    
arm-linux-gcc -c uart.c -o uart.o
    
arm-linux-ld -Ttext 0x30008000 start.o uart.o -o uart
    
arm-linux-objcopy -O binary -S uart uart.bin
                                                
clean:
    
rm 
-f *.o uart.binxyyc


编译运行

   编译运行都OK

本文转自infohacker 51CTO博客,原文链接:http://blog.51cto.com/liucw/1223137

转载地址:http://ulqbx.baihongyu.com/

你可能感兴趣的文章
关于单点登录的理解
查看>>
我的友情链接
查看>>
实际项目中Java多线程模型的总结整理
查看>>
Intel cpu
查看>>
禁用IQKeyboardManager
查看>>
js常用运行库总结
查看>>
MySQL 高可用架构在业务层面细化分析研究
查看>>
我的友情链接
查看>>
windows server 2016 AD安装(一)
查看>>
NAT 服务器配置
查看>>
DC复制错误
查看>>
我的友情链接
查看>>
问题解决Starting MySQL.. ERROR! The server quit without updating PID file
查看>>
Debian包管理系统
查看>>
在Word2010文档中设置和显示隐藏文字
查看>>
powerdesigner that name already exists
查看>>
Boost入门二之thread遇到的坑
查看>>
iptables的conntrack表满了导致访问网站很慢
查看>>
scrapy中Selectors的用法
查看>>
天空下的洗礼
查看>>