LPC17xx Memory Map & Interrupts

From Embedded Systems Learning Academy
Jump to: navigation, search

Memory Map

LPC Memory map can be accessed by using structures, but the "LPC17xx.h" file may be confusing at first to find your LPC registers. The memory map is accessed by structure names followed by structure members. Let's work through an example in which you are trying to find out how to access PINSEL0 mentioned in your LPC datasheet:

  • Open up "LPC17xx.h" (it is in Project/L0 folder)
  • Search for "PINSEL0"
    You will see that this is inside a struct called LPC_PINCON_TypeDef:
  • Now search for "LPC_PINCON_TypeDef" with a #define in the same line.
    You will see that LPC_PINCON is a pointer of this struct
    #define LPC_PINCON ((LPC_PINCON_TypeDef *) LPC_PINCON_BASE)
  • You can now access PINSEL0 by :
    LPC_PINCON->PINSEL0 = XYZ;

At first this may get tedius, but once you get more experience, you won't open the LPC17xx.h file very often.

Example

LPC_SC->PCONP |= (1 << 12);     // Power up ADC


Interrupts on Cortex M3 Core

Unlike the LPC12xx (ARM7) processors, the Cortex M3 core saves interrupt context automatically. Hence no interrupt attribute is needed and furthermore, function address doesn't need to be specified into any control registers since interrupt vector is fixed.

The easiest way to define an interrupt function is to:

  • Look up Interrupt Names in file L0/src/startup.cpp
    Look for declaration of a bunch of functions at this file with keyword ALIAS
    For example: UART0_IRQHandler();
  • Define this function in one of your source code files.
    Enclose in extern "C"{ } tags if you are defining the name in *.cpp file
    extern "C" is not needed if you are defining this in *.c file
  • Enable the Interrupt using CMS Interrupt API:
    NVIC_EnableIRQ(UART0_IRQn);

Example

// Here is the Interrupt Function in a main.cpp file
extern "C"
{
    void UART0_IRQHandler()
    {
    }
}

// Enable Interrupt somewhere in your code:
NVIC_EnableIRQ(UART0_IRQn);