Tuesday , December 18 2018

UART in LPC2148 ARM7 Microcontroller- Serial Communication

In this tutorial, we will communicate microcontroller and PC over serial communication using UART in LPC2148 ARM7 Microcontroller. Before we move on to UART in LPC2148 ARM7. Let’s first discuss UART in general. UART (Universal Asynchronous Receiver/Transmitter) is one of the earliest mode of communication applied to computer (somewhere in 1960s). The information is transmitted one binary bit at a time; as such it is a serial communication method. These bits are grouped together in the form of ‘Frames’ (a set format) for conveying one meaningful piece of data (e.g. character byte). UART is asynchronous because it doesn’t require a transmitter provided clock to synchronize the transmission and receipt of data.

Serial Data Transfer In UART

Serial Data Transmission in UART

Just because there is no clock signal per se, a start bit is added sent first to tell the receiver to listen out for data. The receiver monitors for a logic HIGH falling to logic LOW. The receiver synchronizes its own bus clock to that make up the word being sent, with bit zero, the least significant bit (LSB) being sent first. The bits are sent as pulses on the wire at specific time intervals, set at both ends of links to previously agreed values. The receiver looks at the voltage on the wire at these times; if it sees logic high, it records a binary digit 1 or 0 if the line is low. The receiver checks half way between the start and the end of the pulse to ensure it does not miss-read the voltage on the line during the brief interval while the voltage is rising or falling.

Serial Data Transmission in UART

If two devices use a parity bit for rudimentary error checking, that is calculated and sent next, in sync with data that has been transmitted thus far. Finally, one stop bit is sent by the transmitter. Word length, parity availability and type, and numbers of stop bits all have to be agreed in advance for successful communication because UART uses two wires. The transmitter of device-A connected to receiver of device-B and receiver of device-A connected to transmitter of device-B. This is how devices can send data simultaneously to each other, a mode of communication called ‘full duplex’.

Serial Device Communication

INTRODUCTION: UART in LPC2148 ARM7 Microcontroller

As we all know UART is widely used serial communication protocol in embedded system based applications. Almost all microcontrollers have built-in on-chip UART support. LPC2148 ARM7 core supports two UART in it, UART0 and UART1. UART0 can be used as general purpose UART and also can support ISP Programming through it, whereas UART1 has additional modem support. Both have built in baud rate generator and 16-byte transmit and receive FIFOs. For UART0 the TxD Pin is at P0.0 and RxD Pin is at P0.1 and similarly for UART1 the TxD Pin is at P0.8 and RxD Pin is at P0.9 as shown in table below;

List of UART in LPC2148

RS232 Level Converter

Most of microchips work on TTL or CMOS voltage level which can’t be used to communicate over RS-232 protocol. In this case voltage or level converter is needed which can convert TTL to RS-232 and RS-232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX3232 chip. This chip includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART communication. RS232 communication enables point-to-point data transfer, which often used in data acquisition applications and for data transfer between microcontroller and PC.

In example project, we will use RS232 cable (USB to Serial Converter) to accomplish communication between LPC2148 Microcontroller and PC. *Make sure to install appropriate drivers before you make use of it.

Registers Description: UART in LPC2148 ARM7

Before we use any pin from LPC2148 for serial communication. We have to configure and initialize UART0 Peripheral by setting register bits. Let’s quickly revise functions of UART0 registers which will be used in our code later on. [It is recommended to keep user manual open to collect more details about each register if in case needed].

Registers Description/Function
U0THR Transmit Hold Register: This register contains 8-bit write data which can be transmitted through UART0. This is write only register.
U0RBR Receive Buffer Register: This register contains 8-bit received data from UART0. This data is nothing but top most byte of Rx FIFO. When we use 5, 6 or 7-bit data then remaining bits are padded with 0’s by default. This is read only register.
U0LCR Line Control Register: The value or settings in this register configure the UART0 block. As this is an 8-bit register. There are several parameters configured through this register such as word length, stop bit, parity enable, parity select, break control, divisor latch access bit. This register setting plays important role while initializing UART0 before using it.
U0DLL & U0DLM U0DLL & U0DLM are standard UART0 baud rate generator divider registers. Each of this register holds 8-bit values. Together these registers form a 16-bit divisor value which will be used for baud rate generation. This will be discussed further while code explanation with respect to real world example.
U0FDR Fractional Divider Register: This is another very important register, which plays significant role in baud rate generation. In this 8-bit register, first four bits i.e. Bit[3 to 0]-DIVADDVAL: This is the Prescale Divisor value. If this value is 0 then fractional baud rate generator have no effect on UART0 baud rate. The remaining 4-bits i.e. Bit[4 to 7]-MULVAL: This defines Prescale Multiplier value. Even if fractional baud rate generator is not used the value in this register must be more than or equal to ‘1’.

Calculate Baud Rate for UART in LPC2148 ARM7

Baud Rate for UART in LPC2148 ARM7 Microcontroller can be calculated by given equation:

Baudrate Calculation in LPC2148

Example Project:

Let’s look at real world example where we will send string from LPC2148. This message will be received and displayed on terminal emulator or serial console which configured to appropriate COM Port of PC. I believe now you’re familiar with how UART works. In our program we will use following configuration to establish proper communication:

  • Baud Rate = 9600 baud (with PCLK=60Mhz)
  • Data Length = 8 bits
  • No Parity Bit
  • and 1 Stop Bit

To work out on this project we need following things to be setup:
Software Requirements: Install Keil uVision4, Flash Magic, PuTTY (terminal emulator or serial console)
Hardware Requirements: LPC2148 Development Board, RS232 Cable (USB Serial Converter), Power Adapter (9V-500mA).

Circuit Diagram: UART in LPC2148 ARM7 Microcontroller

UART in LPC2148 ARM Microcontroller
Circuit Diagram-UART in LPC2148 ARM Microcontroller
Connection between LPC2148 and PC

Source Code: UART in LPC2148 ARM7 Microcontroller

Download Project: Click Here

The program is well commented in code itself.  Let’s run code on real hardware to see its impact. Now just compile the code above and load .HEX file onto the LPC2148. We need PuTTY (Terminal Emulator) to observe data sent by LPC2148 Microcontroller over UART0. So here is the setting to configure PuTTY for UART with appropriate COM port, data bits and baud rate etc etc.

IMPORTANT: After loading .hex file, Make sure that you’re not into ISP Mode. We will be using same UART0 for programming as well as for receiving data. In case if you’re using STK2148-UltraLite Board then turned off SW7 switches to read string on PuTTY.

PuTTy Configuration for UART0

Explore Settings Further

Open PuTTY to Read from COM Port

Once we have done with all settings, just open console. And we will start receiving string on PuTTY, sent by LPC2148 Microcontroller. Here is an output from our project:

Output of UART in LPC2148 ARM7 Microcontroller
Output of UART in LPC2148 ARM7 Microcontroller

This is how we can accomplish serial communication using UART in LPC2148 ARM7 Microcontroller to transmit character string from microcontroller to PC. I recommend you to modify the code to explore UART feature in LPC2148. I will try my best to share one more post where we will not only receive but also transmit data. UART will be useful for our future projects where we will display ADC data or output of sensor on terminal emulator. If you have any questions then feel free to leave a comment.

About Umesh Lokhande

Umesh Lokhande holds a Master degree in Scientific Instrumentation from University of Applied Sciences Jena, Germany. and has previously worked at Orbotech, Alere Technologies etc. Umesh is also a founder and first author of BINARYUPDATES.COM


  1. Hi Friends,

    currently I’m working on LPc2148 Micro controller(ARM7).

    Now I need to communicate the PC and and controller using USB interface.
    this controoler has in built USB2.0. I need to read the data from PC and send it to the controller and display on the LCD board which has connected to the controoler
    and vice versa. please post the code and suggest on this.

  2. Hello Venki

    I will soon post article on USB Interface/Protocol in LPC2148 ARM7 Microconroller. But I don’t get your question. Its your project and you have to write code for it. i am not going to write project and post code for you. Now coming back to suggestions I recommend you to look into USB HID example code and modify your code to read data on PC. There are very limited resources on web about USB so it might take for a while to get going…..Good Luck !

  3. while downloading this project showing an error.

  4. Sorry Sarath, I just Fixed broken link. Please let me know, if in case you face any issue while downloading project files.

  5. M.Thirunavukkarasu

    Hello, How to receive ans store the values through UART ?

  6. Very informative.

  7. Hi, Looking for RS232/RS422 TO CAN converter. Any one can help how to build or any ready made solution?

  8. Hi, please help me in doing bluetooth interfacing with lpc2148.

  9. Pratima Nagapurkar

    I need to generate a binary data stream thorugh lpc2148 , stream is taken by user at run time. How should i program uart ???

  10. Nutankumar Naranje

    Hi Umesh,

    I have to do project on embedded system by using ARM7TDMI Processor on LPC2148 Board.
    This project should be based on CAN.

    So can u suggest me the the project based on CAN.

  11. I want to interface GSM with ARM-4. Can you please help me for the code. Where to start the code.

  12. Hi.
    Thank you for your tutorial.But i have a problem associated with PUTTY .”Unable to open connection to COM1 unable to open serial port” i am getting this error message.I have selected the serial line as COM3 and in this error message its shown as COM1.Please help

  13. hi all,

    I want to implement FIFO test case in LPC 2148 micro controller.

    but, i am unable to get concept of the FIFO.

    could you please any one can explian about FIFO concept.

  14. please check in device drivers is installed or not.

    and make sure that you have connected proper port or not,

    do the following procedure

    right click on my computers and go to device manager and check the ports

  15. Hi friends I need to write a program to read a voice in lpc2148 I know how to read a character using uart can v detect a string using UART

  16. Hi friends I need to write a program to read a voice in lpc2148 I know how to read a character using uart can v detect a string using UART


Register | Lost your password?