
Getting Started with NXP's LPC11XX Cortex-M0 ARM
Microcontrollers
Introduction
Hardware
Software
Code Example 0: Toggle a GPIO Pin
Code Example 1: Read a GPIO Pin
Code Example 2: Setting Up the Oscillator
Code Example 3: Transmitting Data Using the UART
Code Example 4: Receiving Data Using the UART
Code Example 5: Using the Analog to Digital Converter (ADC)
Code Example 6: Transmitting with Synchronous Serial Port (SSP/SPI)
Code Example 7: Setting Up the 16bit Timer for PWM
Code Example 8: Transmitting with I2C
Author's Note:
Introduction
Many engineers use 8 bit microcontrollers because of their low cost and ease of use. 32 bit microcontrollers generally offer higher performance
than 8 bit parts, but many believe their cost is significantly higher than bit uCs and that they are more difficult to use than 8 bit parts. While 32 bit
parts are generally a little more complicated than 8 bit parts, the cost of 8 and 32 bit parts aren’t that far apart in many cases. Additionally, the 32
bit parts offer significantly higher performance. In other words, give 32 bit parts a chance!
NXP has introduced a very low cost (i.e. often less than $1 in production volumes) line of 32 bit microcontrollers, the LPC111X family. There are
several other companies also offering some type of ARM Cortex M0 microcontroller. NXP was one of the earliest, but Freescale (Kinetis L), ST
Micro (STM32 F0), and Nuvoton (M051,M058,Mini51,NUC100,NUC122) also have Cortex M0 offerings. This document will give a brief
introduction on how to get up and running using NXP's . The code will work on several other members of the LPC11xx family as well. LPC1114
The assumption inherent in this document is that most engineers follow a fairly similar method of learning when presented with a new
microcontroller family. They start by getting a development kit and trying to toggle a pin, transmit/receive with a serial port, read an ADC pin
etc. This document will show some very simple examples of how to enable and operate these peripherals. This will not be exhaustive of every
operating mode and every peripheral but, it is hoped that it will cover the basics in sufficient detail to allow an engineer to get up and running
quickly. Also included are some tips regarding custom design of PCBs using these parts (see example schematic and BOM below in the
"Hardware" section.
This document is primarily targeted at those who are familiar with 8 bit microcontrollers, but are interested in learning to use a 32 bit part. It is
hoped that this document can make getting started with a 32 bit part as painless as possible. It is realized that this code is very simplistic, and if
one were going to write production code, there would certainly be other features, such as error checking, that would be needed. This code is
provided purely to provide a simplistic “working” example.

Hardware
The examples described in this document will be run on Embedded Artists’ (shown at the top of this wiki page). It should be noted EA-XPR-002
that from Embedded Artists is identical to from NXP. So the two part numbers can be used interchangeably. This EA-XPR-002 OM11049,598
document generally refers to , but that is just for convenience. Any example given in this document should work on both boards EA-XPR-002
using the Code Red Software (discussed below). This PCB can be used standalone, plugged into a solderless , or it can be plugged breadboard
into a dedicated base board such as (shown in Figure 1 below). The or the plugs in on top of this EA-XPR-021 EA-XPR-002 OM11049,598
baseboard and allows you to use the peripherals of the in an easily measurable/observable way. Since this page was first built NXP LPC1114
purchased Embedded Artists and has obsoleted the . So just use the OM11049,598. All the examples should work exactly the EA-XPR-002
same.
NXP's Figure 1: EA-XPR-021
If the (or any other LPC111X device) is being designed into a custom board here are a couple examples of how to connect the part to LPC1114
the programming header (plus part numbers). This circuit was built and successfully tested with the parts indicated.

Ref Des Part Number Digi-Key Part Number Other Options
U1 LPC1114FBD48/302,1 (NXP) 568-5150-ND
J1 534237-6 (TE Connectivity) A26420-ND S5444-ND, A35047-ND
Y1 ABM7-12.000MHZ-D-2-Y-T (Abracon) 535-9836-1-ND
39pF GRM1885C1H390JA01D (Murata) 490-1417-1-ND
1uF EMK107B7105KA-T (Taiyo Yuden) 587-1241-1-ND
Figure 2: Here here are some examples of basic circuits that can be used to get the up and running on a custom board. It should be LC1114
noted that the connector, J1, has the pins on the left and right side shorted together so 1 and 2 are shorted together as are 3 and 4 etc. The
connector, , has the advantage of being very securely attached to the PCB. Other connector options are shown as well. A possible 5535676-7

mating connector for the three connectors given/shown above is from 3M 961108-5604-AR
Figure 3: (TE Connectivity), (TE Connectivity), (Sullins), and (3M) respectively5535676-7 534237-6 PPTC081LGBN-RC 961108-5604-AR

Figure 4
Above (figure 3) is a pictorial example of how the can be used as an inexpensive programmer/debugger. The OM11049,598 OM11049,598
board can be carefully split in two using a “Dremel” tool, at least that’s how separation was accomplished in this case. Wear safety
glasses! Alternatively, I was told by an NXP applications engineer that some customers have found that an old style paper cutter (see Figure 4)

works very well too. If you don't like the idea of cutting the board, the can be used without physically splitting the PCB in two. To OM11049,598
prepare for use without sawing it in half, use an “exacto” knife to cut the traces between the two rows of vias that compose J4. Then solder a
vertical connector into the vias on the programmer/debugger side.
Figure 5: Here a split is used as a programmer/debugger with a custom PCB. In this case, is the connector on OM11049,598 961108-5604-AR
the programmer/debugger and is the mating connector on the custom PCB.PPTC081LGBN-RC
Software
All software examples were written in the C programming language using LPCXpresso v4.1.5 [12/12/2011] development system. This
development environment is available free of charge at ; The comments in the code http://www.support.code-red-tech.com/CodeRedWiki
examples that have a parenthetical note such as (sec 3.5.14) refer to the NXP's "UM10398 LPC11x/LPC11Cxx User Manual" Rev. 12 - 24
September 2012
Important Note: Many of the software examples below write to a register with a name that begins with "LPC_IOCON...". All of these code
samples have been tested and run on real hardware. However on another custom circuit board the author found that in order to successfully
modify these registers the following piece of code had to be included:
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); //enable the clock to the
IOCON block (section 3.5.14)
So if one of the code examples shown here doesn't function correctly. Check and see if one of the "LPC_IOCON..." registers are being
modified. If so, add the line of code above before trying to write to an "LPC_IOCON..." register and see if that fixes the problem. The author
found this to be the solution to a problem experienced when using pin PIO1_1 (pin 34 on the 48 pin QFP part). The pin wouldn't toggle until the
line above was added enabling the clock to the IOCON register. So keep this in mind when using the examples here.
Code Example 0: Toggle a GPIO Pin
This code snippet shows a simple program that was compiled and run on the LPCXpresso board successfully. The program toggles pin 23 on
and off within the infinite while loop. Pin 23 will turn the boards lone LED on and off. For more examples of this type click or (for a plain here here
text file).