如果用Keil ARM的話自動生成的Startup.s中默認VPBDIV=0X00000000,這就導(dǎo)致Fpclk為4分頻。導(dǎo)致波特率下降四倍。以下為keil中的Startup.s中默認設(shè)定的值。;//
;// Peripheral Bus Clock Rate
;//
;// <0=> VPB Clock = CPU Clock / 4
;// <1=> VPB Clock = CPU Clock
;// <2=> VPB Clock = CPU Clock / 2
;//
;// <0=> XCLK Pin = CPU Clock / 4
;// <1=> XCLK Pin = CPU Clock
;// <2=> XCLK Pin = CPU Clock / 2
;//
VPBDIV_SETUP EQU 0VPBDIV_Val EQU 0x00000000我們將其修改為:
VPBDIV_SETUPEQU1
VPBDIV_ValEQU0x00000001
問題解決。
#include
#include"Config.H"
#defineUART_BAUD(baud)(unsignedint)((FOSC*PLL_M)/(baud*16))
voidInit_Uart0(unsignedintBaud)
{
/*initializetheserialinterface*/
PINSEL0=0x00000005;/*EnableRxD0andTxD0*/
U0LCR=0x83;/*8bits,noParity,1Stopbit*/
U0DLM=(unsignedchar)(Baud>>8);
U0DLL=(unsignedchar)Baud;
U0LCR=0x03;/*DLAB=0*/
}
voiddelay(unsignedinti){/*Delayfunction*/
unsignedintn;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}
voidSent_Byte(unsignedchardata)
{
U0THR=data;//發(fā)送數(shù)據(jù)
while((U0LSR&0x40)==0);//等待數(shù)據(jù)發(fā)送完畢
}
voidSent_Str(unsignedcharconst*str)
{while(1)
{if(*str=='/0')break;
Sent_Byte(*str++);//發(fā)送數(shù)據(jù)
}
}
voidmain(void)
{
Init_Uart0(UART_BAUD(115200));
for(;;)
{
Sent_Str("www.dnp.cn/n");
delay(200);
}
}