User manual
LPCXpresso Experiment Kit - User’s Guide
Page 89
Copyright 2013 © Embedded Artists AB
7.13.1 Lab 12a: Generate IRQ via GPIO
In this experiment an interrupt will be generated from a GPIO input. Rebuild the basic breadboard
setup in Figure 13 (on page 39). One LED, controlled by PIO0_2 and one push-button connected to
PIO1_5. Let the push-button input generate an interrupt on a falling edge (= pushing the key). Toggle
the LED every time the push-button is pressed.
Study chapter 12 – L PC111x/LPC11Cxx General Purpose I/O (GPIO) in the LPC111x user’s manual.
Especially note the GPIO features listed (below is an excerpt from user’s manual):
Each individual port pin can serve as an edge or level-sensitive interrupt request.
Interrupts can be configured on single falling or rising edges and on both edges.
Level-sensitive interrupt pins can be HIGH or LOW-active.
Register GPIOnIE (where n is the port number) controls if a pin generates an interrupt, or not. If not, it
is said that the interrupt is masked. Default is that all pin interrupts are masked (inactive). For active
interrupts (non-masked pins), register GPIOnIS controls if a pin generates edge or level sensitive
interrupts. Register GPIOnIEV controls if each individual pin interrupt is falling/rising edge active or
low/high level active. For edge sensitive interrupts, register GPIOnIBE controls if a pin is sensitive to
one edge (rising or falling) or both.
Whether to select an edge or level sensitive interrupt depends on the application and how the
hardware interface works. For the push-button, edge sensitive triggering is suitable since the key press
occupation is what should be detected. How long the key is pressed is of no concern (in this
experiment). If the interrupt would have been level sensitive the interrupts routine (ISR) would have
been activated over and over until the button is no longer pressed. Level sensitive interrupts are
suitable when the ISR can reset the interrupt condition (by some action). Note that the ISR must clear
the interrupt condition for edge sensitive interrupts (check the GPIOxIC register).
Study the code below. It is a framework for the experiment. Note that the main loop does nothing - just
looping in a forever loop. If power consumption is a concern, it is suitable to place the microcontroller in
a low power state. Whenever the interrupt condition occurs the microcontroller will wake up and
execute the ISR and then go back to the low power mode.
/* Define Interrupt Service Routine for Port #1 */
void PIOINT1_IRQHandler (void) //name of function is predefined
{
/* toggle LED on PIO0_2 */
...
/* clear PIO1_5 falling edge interrupt */
LPC_GPIO1->IC = (1<<5); //write with bit 5 set to clear interrupt from PIO1_5
}
void main (void)
{
/* initialize so that PIO1_5 generate an interrupt (falling edge sensitive) */
...
/* enable port #1 interrupt */
NVIC_EnableIRQ(EINT1_IRQn);
/* enter forever loop – let interrupt handle processing */
while(1)
; //here is a potential to go into a low power mode
}
Note that due to contact bouncing (inside the pushbutton) sometimes several edges will be detected
when the pushbutton is pressed. In this experiment this effect is ignored but to in a real system contact
bounce must be handled properly.