• Prototype of combined LPC2132/2138 User Manual created from the design specification.
2004 Sep 13:
• Informatoin on counter functionality of the TIMER0/1 added into "Introduction" and "Timer/Counter0 and Timer/Counter1"
chapters.
• Reference to the LPC201x in Table 23, “Power Control Register (PCON - 0xE01FC0C0),” ("System Control Block" chapter)
replaced with the LPC2132/2138.
• Info on reserved bits in Table 52, “Pin Function Select Register 2 (PINSEL2 - 0xE002C014),” ("Pin Connect Blo ck" chapter)
corrected.
• Reference to the PORT2/3 in the " R egi st er D e sc rip tio n" section of the "GPI O" c ha pter rem ov ed . Nu mbe r o f PO RT0 available
pins discussed in this section also updated.
2004 Sep 14:
• RTC related information added into the "Reset" and "Wakeup Timer" sections of the "System Control Block" chapter.
• "RTC Usage Notes" section in the "Real Time Clock" chapter updated.
2004 Sep 15:
• Count Control Register description in the "Timer/Counter0 and Timer/Counter1" chapter uptaded.
• All available CAP and MAT pins listed in the Pin Description section of the "Timer/Counter0 and Timer/Counter1" chapter.
• Details on the counter mode added into the Count Control register description in the "Timer/Counter0 and Timer/Counter1"
chapter.
2004 Sep 16:
• Typographic errors in the "SSP Controller (SPI1)" chapter corrected.
• Details on Flash erase/write cycles and data retention added into the "Introduction" chapter.
2004 Nov 22:
2
• An updated I
C chapter in cluded in the document.
• Missing chapter on the Memory Accelerator Module (MAM) added to the document.
13November 22, 2004
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
14November 22, 2004
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
1. INTRODUCTION
GENERAL DESCRIPTION
The LPC2131/2132/213 8 microcontrollers are b ased on a 32/16 bit ARM 7TDMI-S™ CPU with real-time em ulation and embedded
trace support, that combines the microcontroller with 32 kB, 64 kB and 512 kB of embedded high speed Flash memory. A 128bit wide memory interface a nd a unique acce lerator architecture enable 32-bit co de execution at maximum clock rate. For critical
code size applica tions , the al ternati ve 16-b it Thum b
Due to their tiny siz e and low p ower consu mption, th ese micr ocontroll ers are ideal f or applica tions where miniat urization is a key
requirement, such as acces s control and point-of-sal e. With a wide range of serial co mmunications inte rfaces and on-chip SRAM
options of 8/16/32 kB, they are very well suited for communication gateways and protocol converters, soft modems, voice
recognition and low en d imaging, provid ing both large buffer si ze and high processi ng power. Various 32-bi t timers, single or dual
10-bit 8 channel ADC(s), 10-bit DAC, PWM channel s and 47 GPIO lines with up to ni ne edge or leve l sensitiv e external interrupt
pins make these microcontrollers particularly suitable for industrial control and medical systems.
FEATURES
• 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.
• 8/16/32 kB of on-chip static RAM and 32/64/512 kB of on-chip Flash program memory. 128 bit wide interface/accelerator
enables high speed 60 MHz operation.
• In-System/In-Applicati on Programming (ISP/IAP) via on-chi p boot-loader softw are. Single Flash sector or ful l chip erase in 400
ms and programming of 256 bytes in 1 ms.
• EmbeddedICE® RT and Embedded Trace interfaces offer real-time debugging with the on-chip RealMonitor™ software and
high speed tracing of instruction execution.
• One (LPC2131/2132) or two (LPC2138) 8 channel 10-bit A/D converters provide a total of up to 16 analog inputs, with
conversion times as low as 2.44 s per chann el.
• Single 10-bit D/A converter provides variable analog output. (LPC2132/2138 only)
• Two 32-bit timers/counters (with four capture and four compare channels each), PWM unit (six outputs) and watchdog.
• Real-time clock equipped with independent power and clock supply permitting extremely low power consumption in powersave modes.
• Multiple serial inte rfaces inc ludin g two UA RTs (16C 550), two Fast I2 C (400 kb it/s), SPI
data length capabilitie s.
• Vectored interrupt controller with configurable priorities and vector addresses.
• Up to 47 of 5 V tolerant general purpose I/O pins in tiny LQFP64 package.
• Up to nine edge or level sensitive external interrupt pins available.
• 60 MHz maximum CPU clock available from programmable on-chip Phase-Locked Loop (PLL) with settling time of 100
microseconds.
• On-chip crystal oscillator with an operating range of 1 MHz to 30 MHz.
• Power saving modes include Idle and Power-down.
• Individual enable/disable of peripheral functions as well as peripheral clock scaling down for additional power optimization.
• Processor wake-up from Power-down mode via external interrupt.
• Single power supply chip with Power-On Reset (POR) and Brown-Out Detection (BOD) circuits:
- CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O pads.
®
Mode reduces code by more t han 30 % wi th min imal perf ormanc e pena lty.
The LPC2131/2132/2138 consists of an ARM7TDM I-S CPU with emulatio n support, the ARM7 Lo cal Bus for interface to on -chip
memory controllers, the AMBA Advanced High-performance Bus (AHB) for interface to the interrupt controller, and the VLSI
Peripheral Bus (VPB, a compatible superset of ARM’s AMBA Advanced Peripheral Bus) for connection to on-chip peripheral
functions. The LPC2131/2132/2138 configures the ARM7TDMI-S processor in little-endian byte order.
AHB peripherals are allocated a 2 megabyte range of addresses at the very top of the 4 gigabyte ARM memory space. Each
AHB peripheral is allocate d a 16 kilobyte address space within the AHB addres s space. LPC2131/2132 /2138 peripheral funct ions
(other than the interrupt controller) are connected to the VPB bus. The AHB to VPB bridge interfaces the VPB bus to the AHB
bus. VPB peripherals are also allocated a 2 megabyte range of addresses, beginning at the 3.5 gigabyte address point. Each
VPB peripheral is allocated a 16 kilobyte address space within the VPB address space.
The connection of on -ch ip pe rip hera ls to dev ic e pi ns is c ont roll ed b y a Pin C onn ec t Bloc k. T his mu st be con fig ure d by soft w are
to fit specific application requirements for the use of peripheral functions and pins.
ARM7TDMI-S PROCESSOR
The ARM7TDMI-S is a general purpose 32-bit microproce ssor, which offers high perfo rmance and very low pow er consumption .
The ARM architecture is based on Reduced Instruction Set Computer (RISC) principles, and the instruction set and related
decode mechanism are much simpler than those of microprogrammed Complex Instruction Set Computers. This simplicity
results in a high instruction throughput and impressive real-time interrupt response from a small and cost-effective processor
core.
Pipeline techniques are em plo ye d so tha t all parts of the processing and memo ry systems can operate continuou sl y. Ty pic al ly,
while one instruction is being executed, its successor is being decoded, and a third instruction is being fetched from memory.
The ARM7TDMI-S processor also employs a unique architectural strategy known as THUMB, which makes it ideally suited to
high-volume applications with memory restrictions, or applications where code density is an issue.
The key idea behind THUMB is that of a super-reduced instruction set. Essentially, the ARM7TDMI-S processor has two
instruction sets:
• The standard 32-bit ARM instruction set.
• A 16-bit THUMB instruction set.
The THUMB set’s 16-bit ins truc tion length allows it to ap proa ch tw ice the density of standard ARM c ode w hil e re tain in g m ost of
the ARM’s performance advantage over a traditional 16-bit processor using 16-bit registers. This is possible because THUMB
code operates on the same 32-bit register set as ARM code.
THUMB code is able to provide up to 65% of the code size of ARM, and 160% of the performance of an equivalent ARM
processor connected to a 16-bit memory system.
The ARM7TDMI-S processor is described in detail in the ARM7TDMI-S Datasheet that can be found on official ARM website.
ON-CHIP FLASH MEMORY SYSTEM
The LPC2131/2132/213 8 inco rporate a 32 k B, 64 kB and 512 kB Flash m emory syste m respecti vely. Thi s memory ma y be used
for both code and data storage. Programming of the Flash memory may be accomplished in several ways: over the serial builtin JTAG interface, using In System Programming (ISP) and UART0, or by means of In Application Programming (IAP)
capabilities. The app lication program, us ing the In App lication Pro gramming (IAP) function s, may also e rase and/or p rogram the
Flash while the application is running, allowing a great degree of flexibility for data storage field firmware upgrades, etc. When
the LPC2131/2132/2138 on-chip bootloader is used, 32/64/500 kB of Flash memory is available for user code.
Introduction17November 22, 2004
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
The LPC2131/2132/2138 Flash memory provides minimum of 10,000 erase/write cycles and 10 years of data-retention.
ON-CHIP STATIC RAM
On-Chip static RAM (SRAM ) may b e used for code and/or d ata sto rage. The SRAM may be acc essed as 8-bits, 16 -bit s, and 3 2bits. The LPC2131/2132/2138 provide 8/16/32 kB of static RAM respectively.
The LPC2131/LPC2132/ 2138 SRAM is des igned to be acce ssed as a by te-address ed memory. Word an d halfword acc esses to
the memory ignore the al ignme nt of the add ress an d access the natural ly-ali gned va lue t hat is add ressed (so a memory access
ignores address bits 0 and 1 for word acces ses, and ignores bit 0 for halfword acc esses). Therefore valid reads and w rites require
data accessed as halfwords to originate from addresses with address line 0 being 0 (addresses ending with 0, 2, 4, 6, 8, A, C,
adnd E) and data a ccessed as wo rds to origina te from adres ses with add ress l ines 0 and 1 bein g 0 (a ddress es endin g wi th 0, 4 ,
8, and C). This rule applies to both off and on-chip memory usage.
The SRAM controller inc orpo rate s a wri te-b ac k bu ffer i n ord er to p rev ent CPU stalls during back -to- bac k wr i tes . The write-b ac k
buffer always holds the last data sent by software to the SRAM. This data is only written to the SRAM when another write is
requested by software (the data is only written to the SRAM when software does another write). If a chip reset occurs, actual
SRAM contents will not reflect the most recent write request (i.e. after a "warm" chip reset, the SRAM does not reflect the last
write operation). Any software that checks SRAM contents after reset must take this into account. Two identical writes to a
location guarantee that the data will be present after a Reset. Alternatively, a dummy write operation before entering idle or
power-down mode will similarly guarantee that the last data written will be present in SRAM after a subsequent Reset.
Introduction18November 22, 2004
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
BLOCK DIAGRAM
ARM7 Local Bus
Internal SRAM
Controller
8/16/32 kB
SRAM
EINT3:0
8 x CAP0
8 x MAT
AD0.7:0
2
AD1.7:0
3
A
out
Internal Flash
Controller
32/64/512 kB
FLASH
External
Interrupts
Capture / Compare
(w/ external clock)
TIMER 0 & 1
A/D Converters
0 and 1
D/A Converter
2
2
1
1
TMS
TRST
Test/Debug Interface
1
1
1
TDI
TCK
TDO
ARM7TDMI-S
AHB Bridge
AHB to VPB
Bridge
VPB (VLSI
Peripheral Bus)
PLL
System
Module
Emulation Trace
(Advanced High-performance Bus)
Clock
AMBA AHB
VPB
Divider
I2C Serial
Interfaces 0 and 1
SPI and SSP
Serial Interfaces
UART 0 & 1
Real Time
Clock
Xtal2
Xtal1
RESET
System
Functions
Vectored Interrupt
Controller
AHB
Decoder
SCL0,1
SDA0,1
SCK0,1
MOSI0,1
MISO0,1
SSEL0,1
TxD0,1
RxD0,1
DSR12,CTS12,RTS1
DTR12, DCD12,RI1
RTXC1
RTXC2
V
bat
2
2
P0.31:0
P1.31:16, 1:0
PWM6:1
1
Shared with GPIO.
2
LPC2138 only.
3
LPC2132/2138 only.
2
General
Purpose I/O
PWM0
Watchdog
Timer
System
Control
Figure 1: LPC2131/2132/2138 Block Diagram
Introduction19November 22, 2004
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
Introduction20November 22, 2004
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
2. LPC2131/2132/2138 MEMORY ADDRESSING
MEMORY MAPS
The LPC2131/2132 /2138 incorporates several distinct memory r egions, shown in t he following figures. Figure 2 shows the overall
map of the entire addr ess sp ace fro m the user p rogra m view point fo llow ing reset. Th e interr upt vec tor area s upport s address remapping, which is described later in this section.
- AHB section is
128 x 16 kB blocks
(totaling 2 MB).
- VPB section is
128 x 16 kB blocks
(totaling 2 MB).
4.0 GB
4.0 GB - 2 MB
3.75 GB
AHB Peripherals
0xFFFF FFFF
0xFFE0 0000
0xFFDF FFFF
Reserved
0xF000 0000
0xEFFF FFFF
Reserved
3.5 GB + 2 MB
0xE020 0000
0xE01F FFFF
VPB Peripherals
3.5 GB
0xE000 0000
Figure 3: Peripheral Memory Map
Figures 3 through 5 show different views of the peripheral address space. Both the AHB and VPB peripheral areas are 2
megabyte spaces whic h are divided up into 128 periph erals. Each peripheral space is 16 kilobytes in size . This allows simplifyi ng
the address decod ing for ea ch perip heral. All periphera l registe r addresses are wor d aligned (to 32-bit b oundar ies) regard less of
their size. This eliminate s th e nee d for byte lane mapping hardwa re tha t w oul d be requi red to all ow by te (8-bit) or half-word (16bit) accesses to occur at smaller boundaries. An implication of this is that word and half-word registers must be accessed all at
once. For example, it is not possible to read or write the upper byte of a word register separately.
LPC2131/2132/2138 MEMORY RE-MAPPING AND BOOT BLOCK
Memory Map Concepts and Operating Modes
The basic concept on the LPC21 31/2132/2138 is that each mem ory area has a " natural " location i n the memo ry map. Thi s is the
address range for which code residing in that area is written. The bulk of each memory space remains permanently fixed in the
same location, eliminating the need to have portions of the code designed to run in different address ranges.
Because of the location of the interrupt vectors on the ARM7 processor (at addresses 0x0000 0000 through 0x0000 001C, as
shown in Table 2 below), a sma ll portion of the Boot Blo ck and SRAM spa ces need to be re-ma pped in order to al low alternati ve
uses of interrupts in the different operating modes described in Table 3. Re-mapping of the interrupts is accomplished via the
Memory Mapping Control feature described in the System Control Block section.
*: Identified as reserved in ARM do cumen tation , this loca tion is us ed by the Boot Loader as the Valid User Progra m key. Thi s is
descibed in detail in Flash Memory System and Programming on page 225.
Table 3: LPC2131/2132/2138 Memory Mapping Modes
ModeActivationUsage
Boot Loader
mode
User Flash
mode
User RAM
mode
Hardware activation
by any Reset
Software activation
by Boot code
Software activation
by User program
The Boot Loader always
mapped to the bottom of memory to allow handling exceptions and using interrupts
during the Boot Loading process.
Activated by Boot Loader whe n a valid User Program Si gnature is recogni zed in memory
and Boot Loader operation is not forced. Interrupt vectors are not re-mapped and are
found in the bottom of the Flash memory.
Activated by a User Program as de sir ed. In terru pt ve ctors are re-mapped to the bottom
of the Static RAM.
executes after any reset. The Boot Block interrupt vectors are
In order to allo w for com patibili ty with future der ivatives , the en tire Boot Block i s mapped to the top of t he on -chip mem ory space.
In this manner, the use of larger or smaller flash modules will not require changing the location of the Boot Block (which would
require changing the Boot Loader code itself ) or changing the mappin g of the Boot Block interru pt vectors. Memo ry spaces other
than the interrupt vectors remain in fixed locations. Figure 6 shows the on-chip memory mapping in the modes defined above.
The portion of memory that is re-mapped to allow interrupt processing in different modes includes the interrupt vector area (32
bytes) and an additional 32 bytes, for a total of 64 bytes. The re-mapped code locations ove rlay addresses 0x0000 0000 throu gh
0x0000 003F. A typical u ser progra m in th e Flash memory c an place the entir e FIQ h andler at addre ss 0x0000 001C w ithout a ny
need to consider memory boundaries. The vector contained in the SRAM, external memory, and Boot Block must contain
branches to the actual interrupt handlers, or to other instructions that accomplish the branch to the interrupt handlers.
There are three reasons this configuration was chosen:
1. To give the FIQ handler in the Flash memory the advantage of not having to take a memory boundary caused by the remapping into account.
2. Minimize the need to for th e SRAM and Bo ot Blo ck vec to rs to deal with arbitrary boun dari es in th e mi ddl e of cod e sp ac e.
3. To provide space to store constants for jumping beyond the range of single word branch instructions.
Re-mapped memory are as, includin g the Boot Block and interr upt vectors, con tinue to appear in their original loc ation in additi on
to the re-mapped address.
Details on re-mapping and examples can be found in System Control Block on page 29.
The LPC2131/2132/2138 ge nerates the ap propriate bus cycle abort exce ption if an acc ess is attempte d for an address tha t is in
a reserved or unassigned address region. The regions are:
• Areas of the memory map that are not implemented for a specific ARM derivative. For the LPC2131/2132/2138, this is:
- Address space between On-Chip Non-Volatile Memory and On-Chip SRAM, labelled "Reserved Addressing Space" in
Figure 2 and Figure 6. For 32 kB Flash device this is memory address range from 0x0000 8000 to 0x3FFF FFFF, for 64 kB
Flash device this is memory address range from 0x0001 0000 to 0x3FFF FFFF, while for 512 kB Flash device this range is
from 0x0008 0000 to 0x3FFF FFFF.
- Address space between On-Chi p S ta tic RAM and Ex ternal Me mory. Labell ed "Rese rved Ad dressing Space" in Figure 2. For
8 kB SRAM device this is memory address range from 0x4000 1FFF to 0x7FFF DFFFF, for 16 kB SRAM device this is
memory address range from 0x4000 3FFF to 0x7FFF DFFF, while for 32 kB SRAM device this range is from 0x4000 7FFF
to 0x7FFF D000. This is an address range from 0x4000 3FFF to 0x7FFF D000.
- Reserved regions of the AHB and VPB spaces. See Figure 3.
• Unassigned AHB peripheral spaces. See Figure 4.
• Unassigned VPB peripheral spaces. See Figure 5.
For these areas, both atte mpted data acc ess and instruc tion fetch gen erate an excep tion. In additi on, a Prefetch Abort exceptio n
is generated for any instruction fetch that maps to an AHB or VPB peripheral address.
Within the addres s spa ce of an ex is tin g VPB peri phe ral, a data abort exception is not genera ted in res po ns e to an ac ce ss to an
undefined address. Address decoding within eac h peri phe ral is li mit ed to that ne ede d to di stinguish defined regist ers wi thin the
peripheral itself. Fo r example, an access to address 0xE0 00D000 (an un defined add ress wit hin the UART0 space) may result in
an access to the register defined at address 0xE000C000. Details of such address aliasing within a peripheral space are not
defined in the LPC2131/2132/2138 documentation and are not a supported feature.
Note that the ARM core stores the Prefetch Abort flag along with the associated instruction (which will be meaningless) in the
pipeline and processes the abort only if an attempt is made to execute the instruction fetched from the illegal address. This
prevents acciden tal abort s that co uld be ca used by prefetc hes tha t occur w hen co de is ex ecute d very ne ar a memo ry boun dary.
The System Control Block includes several system features and control registers for a number of functions that are not related
to specific peripheral devices. These include:
• Crystal Oscillator.
• External Interrupt Inputs.
• Memory Mapping Control.
•PLL.
• Power Control.
•Reset.
• VPB Divider.
• Wakeup Timer.
Each type of fu nction has it s own reg ister(s) if any are required and unnee ded bits a re defined as reserved i n order to allow future
expansion. Unrelated functions n ever share the same register addresses.
PIN DESCRIPTION
Table 4 shows pins that are associated with System Control block functions.
Table 4: Pin summary
Pin namePin directionPin Description
X1InputCrystal Oscillator Input- Input to the oscillator and internal clock generator circuits.
X2OutputCrystal Oscillator Output- Output from the oscillator amplifier.
External Interrupt Input 0- An ac tive low general p urpose interru pt input. This pin may be
EINT0Input
EINT1Input
EINT2Input
used to wake up the processor from Idle or Power down modes.
Pins P0.1 and P0.16 can be selected to perform EINT0 function.
External Interrupt Input 1- See the EINT0 description above.
Pins P0.3 and P0.14 can be selected to perform EINT1 function.
LOW level on pin P0.14 immediately after reset is considered as an external hardware
request to start the ISP c ommand handler. M ore details on I SP and Serial Boot Load er can
be found in "Flash Memory System and Programming" chapter.
External Interrupt Input 2- See the EINT0 description above.
Pins P0.7 and P0.15 can be selected to perform EINT2 function.
External Interrupt Input 3- See the EINT0 description above.
EINT3Input
Pins P0.9, P0.20 and P0.30 can be selected to perform EINT3 function.
R
ESETInput
System Control Block29November 22, 2004
External Reset input- A low on this pin resets the chi p, causing I/O ports and periphe rals
to take on their default states, and the processor to begin execution at address 0.
P
hilips SemiconductorsPreliminary User Manu
al
LPC2131/2132/2138ARM-based Microcontroller
REGISTER DESCRIPTION
All registers, regardless of size, are on word address boundaries. Details of the registers appear in the description of each
function.
Table 5: Summary of System Control Registers
NameDescriptionAccess
External Interrupts
EXTINTExternal Interrupt Flag Register.R/W00xE01FC140
EXTWAKE External Interrupt Wakeup Register.R/W00xE01FC144
EXTMODE External Interrupt Flag Register.R/W00xE01FC148