The baud rate of the newly created UART0 communication is inconsistent (the baud rate is reduced by 4 times)

Publisher:渤海湾Latest update time:2017-01-03 Source: eefocusKeywords:UART0 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

If you use Keil ARM, the default value of VPBDIV=0X00000000 in the automatically generated Startup.s will result in Fpclk being divided by 4, which will cause the baud rate to drop by four times. The following are the default values ​​set in Startup.s in Keil. ;// VPBDIV Setup
;// Peripheral Bus Clock Rate
;// VPBDIV: VPB Clock
;// <0=> VPB Clock = CPU Clock / 4
;// <1=> VPB Clock = CPU Clock
;// <2=> VPB Clock = CPU Clock / 2
;// XCLKDIV: XCLK Pin
;// <0=> XCLK Pin
= CPU Clock / 4;// < 1=> XCLK
Pin = CPU Clock;// <2=>

VPBDIV_SETUP EQU 1

VPBDIV_Val EQU 0x00000001

problem solved.

  1. #include

  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; // Send data


  25.    while( (U0LSR&0x40)==0 ); // Wait for data to be sent

  26. }

  27. void Sent_Str(unsigned char const *str)

  28. { while(1)

  29.    { if( *str == '/0' ) break;

  30.       Sent_Byte(*str++); // Send data

  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.  }


Keywords:UART0 Reference address:The baud rate of the newly created UART0 communication is inconsistent (the baud rate is reduced by 4 times)

Previous article:Introduction to LPC2131 UART usage
Next article:CRC check is used in STM32 and C#

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号