/* 手册定好的计算方式,不需要问为什么,直接套公式即可。DIV_VAL = (40000000/(115200 x 16)) – 1= 21.7 – 1= 20.7UBRDIVn = 20 (integer part of DIV_VAL)UFRACVALn/16 = 0.7 So, UFRACVALn = 11*/50000000 / (115200 * 16) - 1 = 27.13 - 1 = 26.13 = 26 【==UBRDIV0】0.13 * 16 = 2.08 = 2 【==UFRACVAL0】【汇总】S5P6818UART相关寄存器1) UART行控制器ULCONn - 设置数据格式2) UART模式控制寄存器UCONn - 用来选择时钟源,发送/接收数据可选轮询3) UART FIFO控制寄存器UFCONn4) UART MODEM控制寄存器UMCONn5) 发送寄存器UTXH、接收寄存器URXH6) 波特率分频寄存器UBRDIV,UFRACVAL7) GPIO相关寄存器8) 中断相关寄存器9) 时钟、电源控制寄存器4. 编码/** 代码演示 - main.c **/#include "uart.h"void main (void) { // 8N1 115200 non-FIFO polling uart_init ( ); while (1) { uart_puts ("/n hello,world!"); } }/** 代码演示 - uart.c **/#define UART0CLKENB *((volatile unsigned int*)0xc00a9000)#define UART0CLKGEN0L *((volatile unsigned int*)0xc00a9004)#define GPIOD_ALTFN0 *((volatile unsigned int*)0xc001d020)#define GPIOD_ALTFN1 *((volatile unsigned int*)0xc001d024)#define GPIOD_PULLENB *((volatile unsigned int*)0xc001d060)#define ULCON0 *((volatile unsigned int*)0xc00a1000)#define UCON0 *((volatile unsigned int*)0xc00a1004)#define UFCON0 *((volatile unsigned int*)0xc00a1008)#define UTRSTAT0 *((volatile unsigned int*)0xc00a1010)#define UTXH0 *((volatile unsigned int*)0xc00a1020)#define URXH0 *((volatile unsigned int*)0xc00a1024)#define UBRDIV0 *((volatile unsigned int*)0xc00a1028)#define UFRACVAL0 *((volatile unsigned int*)0xc00a102c)void uart_init (void) { /* uart0 clk disable */ UART0CLKENB &= ~(1 << 2); // GPIOD18(Tx 接收管脚) GPIOD14(Rx 发送管脚) 配置功能Function1 GPIOD_ALTFN0 &= ~(3 << 28); // GPIOD14 GPIOD_ALTFN0 |= (1 << 28); GPIOD_ALTFN1 &= ~(3 << 4); // GPIOD18 GPIOD_ALTFN1 |= (1 << 4); // 时钟配置:选择PLL[1] 800MHz UART0CLKGEN0L &= ~(7 << 2); UART0CLKGEN0L |= (1 << 2); // 分频设置 800/(0x0f+1)=50MHz UART0CLKGEN0L &= ~(0xff << 5); // [12:5] 8个位 UART0CLKGEN0L |= (0xf << 5); // [12:5] 4个位设置为1111 // UART控制器设置 ULCON0 = 0x03; // 8N1 UCON0 = 0x05; // 0101 == 0x05 polling UFCON0 &= ~(1 << 0); // non-FIFO disable UBRDIV0 = 26; // 50000000/(115200*16) - 1 == 26.13 UFRACVAL0 = 2; // 0.13*16 == 2.08 /* uart0 clk enable */ UART0CLKENB |= (1 << 2);}void uart_putc (char c) { // UTRSTAT0 bit[1] == 1, 缓存寄存器为empty // 轮询是否为空 while (! (UTRSTAT0 & 0x02)); // !(空) 什么都不干。 UTXH0 = c; if (c == '/n') uart_putc ('/r');}void uart_puts (char* str) { if (! str) return ; while (*str) { uart_putc (*str); str++; }}/** 代码演示 - uart.h **/#ifndef _UART_H_#define _UART_H_extern void uart_init (void);extern void uart_puts (char*);#endif //_UART_H_5. 编译
$:' arm-cortex_a9-linux-gnueabi-gcc -c -nostdlib main.c -o main.o$:' arm-cortex_a9-linux-gnueabi-gcc -c -nostdlib uart.c -o uart.o$:' arm-cortex_a9-linux-gnueabi-ld -nostdlib -nostartfiles -Ttext=48000000 -emain main.o uart.o -o uart // 注意.o文件顺序$:' arm-cortex_a9-linux-gnueabi-objcopy -O binary uart uart.bin6. 运行$:' sudo cp uart.bin /tftpboot/X6818#:' tftp 48000000 uart.binX6818#:' go 48000000
新闻热点
疑难解答