建立的UART0通訊傳輸速率不一致的問題(傳輸速率降低4倍)

來源:互聯網
上載者:User
如果用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

問題解決。

  1. #include <LPC213X.H>
  2. #include "Config.H"
  3. #define UART_BAUD(baud) (unsigned  int)((FOSC*PLL_M) / (baud * 16))
  4. void Init_Uart0(unsigned int Baud)
  5.  {
  6.    /* initialize the serial interface   */
  7.   PINSEL0 = 0x00000005;           /* Enable RxD0 and TxD0                     */
  8.   U0LCR = 0x83;                   /* 8 bits, no Parity, 1 Stop bit            */
  9.   U0DLM=(unsigned char)(Baud>>8);
  10.   U0DLL = (unsigned char)Baud;                     
  11.   
  12.   U0LCR = 0x03;                   /* DLAB = 0     */
  13.  }
  14. void delay (unsigned int i) {                      /* Delay function */
  15. unsigned int n;
  16. while(i>1)
  17. {
  18.     for(n=65535;n>1;n--);
  19.     i--;
  20. }
  21. }
  22. void  Sent_Byte(unsigned char data)
  23. {  
  24.     U0THR = data;                   // 發送資料
  25.    while( (U0LSR&0x40)==0 );        // 等待資料發送完畢
  26. }
  27. void  Sent_Str(unsigned char const *str)
  28. {  while(1)
  29.    {  if( *str == '/0' ) break;
  30.       Sent_Byte(*str++);        // 發送資料
  31.    }
  32. }
  33.  void main(void)
  34.  {
  35.     
  36.      Init_Uart0(UART_BAUD(115200));
  37.     
  38.      for(;;)
  39.      {
  40.         Sent_Str("www.dnp.cn /n") ;
  41.         delay(200);
  42.      }
  43.  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.