如果用Keil ARM的話自動產生的Startup.s中預設VPBDIV=0X00000000,這就導致 Fpclk 為4分頻。導致傳輸速率下降四倍。以下為keil中的Startup.s中預設設定的值。;// <e> VPBDIV Setup
;// <i> Peripheral Bus Clock Rate
;// <o1.0..1> VPBDIV: VPB Clock
;// <0=> VPB Clock = CPU Clock / 4
;// <1=> VPB Clock = CPU Clock
;// <2=> VPB Clock = CPU Clock / 2
;// <o1.4..5> XCLKDIV: XCLK Pin
;// <0=> XCLK Pin = CPU Clock / 4
;// <1=> XCLK Pin = CPU Clock
;// <2=> XCLK Pin = CPU Clock / 2
;// </e>
VPBDIV_SETUP EQU 0VPBDIV_Val EQU 0x00000000我們將其修改為:
VPBDIV_SETUP EQU 1
VPBDIV_Val EQU 0x00000001
問題解決。
- #include <LPC213X.H>
- #include "Config.H"
- #define UART_BAUD(baud) (unsigned int)((FOSC*PLL_M) / (baud * 16))
- void Init_Uart0(unsigned int Baud)
- {
- /* initialize the serial interface */
- PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0 */
- U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
- U0DLM=(unsigned char)(Baud>>8);
- U0DLL = (unsigned char)Baud;
-
- U0LCR = 0x03; /* DLAB = 0 */
- }
- void delay (unsigned int i) { /* Delay function */
- unsigned int n;
- while(i>1)
- {
- for(n=65535;n>1;n--);
- i--;
- }
- }
- void Sent_Byte(unsigned char data)
- {
- U0THR = data; // 發送資料
- while( (U0LSR&0x40)==0 ); // 等待資料發送完畢
- }
- void Sent_Str(unsigned char const *str)
- { while(1)
- { if( *str == '/0' ) break;
- Sent_Byte(*str++); // 發送資料
- }
- }
- void main(void)
- {
-
- Init_Uart0(UART_BAUD(115200));
-
- for(;;)
- {
- Sent_Str("www.dnp.cn /n") ;
- delay(200);
- }
- }