LPC1768 serial port UART0

Publisher:blazingsLatest update time:2016-04-06 Source: eefocusKeywords:LPC1768 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Serial port operation, first power on, clock control turned on.

Then the pin selection is set to serial port mode.

Then set the serial port transmission data format.

Baud rate setting, (note that the baud rate is different when there are decimal places and when there are no decimal places. If there are decimal places, DIVADDL and MULVAL need to be set).

The baud rate is then latched.

Settings control the operation of UARTn RX and TX FIFO.

Finally, turn on the interrupt of UART0 in the system and enable the receive interrupt.

See the code for details, which is commented in detail.

  1.   
  2.   
  3. #include LPC17XX.h  
  4.   
  5.   
  6. #define  FOSC                         12000000                              
  7. #define  FCCLK                       (FOSC   8)                            
  8.                                                                                        
  9. #define  FCCO                        (FCCLK  3)                            
  10.                                                                                        
  11. #define  FPCLK                       (FCCLK  4)                             
  12.                                                                                         
  13.   
  14. int  Uart0RecvBuf;                    //  UART0  RX  DATA  
  15.   
  16. void  Uart0Init(uint32_t  bps)   
  17.  
  18.     LPC_SC->PCONP  |=  (1<<3);                          //Turn on UART0 power and clock control bits  
  19.   
  20.     LPC_PINCON->PINSEL0  0X00000050;         //P0.2  P0.3 are set to serial port  
  21.   
  22.     LPC_UART0->LCR  0x83;                          //Set the serial port data format, 8-bit character length, 1 stop bit, no checksum,  
  23.                                                                    // Enable access to the divisor latch  and set the baud rate  
  24.     LPC_UART0->DLM  ((FPCLK/16)/bps)  256;  //The divisor has eight high bits   no decimals  
  25.     LPC_UART0->DLL  ((FPCLK/16)/bps)  256; //The eighth digit of the divisor  
  26.   
  27.     LPC_UART0->LCR  0x03;                          //Disable access to the divisor latch and lock the baud rate  
  28.   
  29.     LPC_UART0->FCR   0x07;                        //Control the operation of UARTn  RX and TX  FIFO. Receive one byte of data to trigger an interrupt  
  30.   
  31.     NVIC_EnableIRQ(UART0_IRQn);                   
  32.     LPC_UART0->IER  0x01;                        //Enable receive interrupt  
  33.  
  34.   
  35. int  Uart0RecvByte(void)    //Query method  
  36.  
  37.     //When UnRBR contains unread characters, UnLSR[0] will be set; when UARTn  RBR  FIFO is empty, UnLSR[0] will be cleared  
  38.     //0    UnRBR is empty  
  39.     //1    UnRBR contains valid data  
  40.     while(!((LPC_UART0->LSR)  0x01));        //Wait to determine whether LSR[0] is 1. If it is 1, it means that data has been received in RBR        
  41.       
  42.     return(LPC_UART0->RBR);                    //Read received data  
  43.  
  44.   
  45. int  Uart0SendByte(int  buf)  
  46.  
  47.     //When UARTn THR is detected  to be empty, THRE will be set immediately. Writing UnTHR will clear THRE  
  48.     //0    UnTHR contains valid characters  
  49.     //1    UnTHR is empty  
  50.     while(!((LPC_UART0->LSR)  0x01));        //Wait to determine whether LSR[5] (THRE) is 1. If it is 1, it means THR is empty.        
  51.       
  52.     LPC_UART0->THR  buf;                      //Send data  
  53.   
  54.     return  0;  
  55.  
  56.   
  57. void  UART0_IRQHandler(void)  
  58.  
  59.     Uart0RecvBuf  LPC_UART0->RBR;        //Read received data      
  60.   
  61.     Uart0SendByte(Uart0RecvBuf);            //Send received data  
  62.  
  63.   
  64.   
  65. int  main(void)  
  66.  
  67.     int  temp;  
  68.   
  69.     SystemInit();  
  70.     Uart0Init(115200);  
  71.   
  72.     while(1)  
  73.      
  74.                       
  75.     //   temp  Uart0RecvByte();          //Query received data  
  76.     //   Uart0SendByte(temp);             //Send data  
  77.   
  78.      
  79.   
  80. }  
Keywords:LPC1768 Reference address:LPC1768 serial port UART0

Previous article:LPC1768 CPU clock configuration
Next article:ARM boot process (Cortex-M3 NXP LPC1768 as an example)

Recommended ReadingLatest update time:2024-11-16 23:48

LPC1768 USB driver (Part 3) ----LPC1768 USB module
(Figure 1) USB device controller block diagram Module Introduction: AHB: Mainly used for connection between high-performance modules (CPU, DMA and DSP, etc.); USB ATX: The analog transceiver built into the USB device controller is used to send and receive D+ and D- signals on the USB bus; SIE (SERIAL INTERFACE ENGIN
[Microcontroller]
LPC1768 USB driver (Part 3) ----LPC1768 USB module
LPC1768 serial port UART0
Serial port operation, first power on, clock control turned on. Then the pin selection is set to serial port mode. Then set the serial port transmission data format. Baud rate setting, (note that the baud rate is different when there are decimal places and when there are no decimal places. If there are decimal pla
[Microcontroller]
IIS communication of LPC1768
IIS is a digital bus for audio transmission defined by Philips. LPC1768 supports this bus. The I2S interface is a 3-wire serial bus with 1 data line, 1 clock line and 1 word selection signal line. The basic I2S connection has a host (which is always the host) and a slave. The I2S of the LPC1700 series Cortex-M3 microc
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号