mini2440串口有三个独立通道:每个通道可以工作在中断,查询,DMA模式。
在本实验中,使用串口要设置UBRDIVn波特率,ULCONn 传输格式,UCONn时钟源等,使用串口0,工作于查询方式。
用secureCRT登录后往在串口上输入一个数据,目标版收到将ascii码加一从串口输出输出到CRT,设备支持最多64字节数据发送。
代码如下:
1,serial.c
#define GPHCON (*(volatile unsigned long *)0x56000070)
#define GPHUP (*(volatile unsigned long *)0x56000078)
#define ULCON0 (*(volatile unsigned long *)0x50000000)
#define UCON0 (*(volatile unsigned long *)0x50000004)
#define UFCON0 (*(volatile unsigned long *)0x50000008)
#define UMCON0 (*(volatile unsigned long *)0x5000000c)
#define UBRDIV0 (*(volatile unsigned long *)0x50000028)
#define UTRSTAT0 (*(volatile unsigned long *)0x50000010)
#define UTXH0 (*(volatile unsigned char *)0x50000020)
#define URXH0 (*(volatile unsigned char *)0x50000024)
#define PCLK 50000000
#define UART_CLK PCLK
#define UART_BAUD_RATE 115200
#define UART_BRD ((UART_CLK / (UART_BAUD_RATE * 16)) - 1)
#define TXD0READY (1<<2)
#define RXD0READY (1)
void uart0_init(void)
{
GPHCON |= 0xa0;
GPHUP = 0x0c;
ULCON0 = 0x03;
UCON0 = 0x05;
UFCON0 = 0x00;
UMCON0 = 0x00;
UBRDIV0 = UART_BRD;
}
void putc(unsigned char c)
{
while (!(UTRSTAT0 & TXD0READY));
UTXH0 = c;
}
unsigned char getc(void)
{
while (!(UTRSTAT0 & RXD0READY));
return URXH0;
}
int isDigit(unsigned char c)
{
if (c >= '0' && c <= '9')
return 1;
else
return 0;
}
int isLetter(unsigned char c)
{
if (c >= 'a' && c <= 'z')
return 1;
else if (c >= 'A' && c <= 'Z')
return 1;
else
return 0;
}
int main()
{
unsigned char c;
uart0_init();
while(1)
{
c = getc();
if (isDigit(c) || isLetter(c))
putc(c++);
}
return 0;
}
程序中未涉及.h文件的应用,这涉及到makefile的编写,努力未果。
2,crt0.s
.text
.global _start
_start:
ldr r0, =0x53000000
mov r1,#0x0
str r1,[r0]
ldr sp, =1024*4
ldr r0, =0x4c000014
mov r1,#0x03
str r1,[r0]
mrc p15,0,r1,c1,c0,0
ORR r1,r1,#0xc0000000
mcr p15,0,r1,c1,c0,0
ldr r0,=0x4c000004
ldr r1,=((0x5c<<12)|(0x01<<4)|(0x02))
str r1,[r0]
bl main
halt_loop:
b halt_loop
和前一个实验一样,这里把系统时钟的设置加到了初始化文件中。
3, makefile
serial.bin:crt0.s serial.c
arm-linux-gcc -g -c -o crt0.o crt0.s
arm-linux-gcc -g -c -o serial.o serial.c
arm-linux-ld -Ttext 0x00000000 -g crt0.o serial.o -o serial_elf
arm-linux-objcopy -O binary -S serial_elf serial.bin
clean:
rm -f serial.bin serial_elf *.o
c:
cp serial.bin /home/armshare/zengh/
在上一句中我们make c就把bin文件拷到了我们的共享目录下。
将继续在makefile上研究。
下一blog将对中断进行研究。
serial.zip
阅读(1174) | 评论(0) | 转发(2) |