The new uart0 communication baud rate is inconsistent (the baud rate is reduced by 4 times)

Source: Internet
Author: User
If Keil arm is used, vpbdiv = 0x00000000 is automatically generated in startup. S, which leads to fpclk dividing by 4. The baud rate is reduced by four times. The default value of startup. s in Keil is as follows .; // <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 we will change it:

Vpbdiv_setup equ 1

Vpbdiv_val equ 0x00000001

Solve the problem.

  1. # Include <lpc20.x. 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. U0lcr = 0x03;/* dlab = 0 */
  12. }
  13. Void delay (unsigned int I) {/* Delay function */
  14. Unsigned int N;
  15. While (I> 1)
  16. {
  17. For (n = 65535; n> 1; n --);
  18. I --;
  19. }
  20. }
  21. Void sent_byte (unsigned char data)
  22. {
  23. U0thr = data; // send data
  24. While (u0lsr & 0x40) = 0); // wait for the data to be sent
  25. }
  26. Void sent_str (unsigned char const * Str)
  27. {While (1)
  28. {If (* STR = '/0') break;
  29. Sent_byte (* STR ++); // send data
  30. }
  31. }
  32. Void main (void)
  33. {
  34. Init_uart0 (uart_baud (115200 ));
  35. For (;;)
  36. {
  37. Sent_str ("www.dnp.cn/N ");
  38. Delay (200 );
  39. }
  40. }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.