10 years, 7 months ago.

lpc11u24 Simple deepsleep and interrupt wakeup example

I tried to use the lpc11u24 Simple deepsleep and interrupt wakeup example on the mbed NXP LPC11U24 Handbook page, and just tried to flash some LEDs after wakeup:

Simple deepsleep wakeup

#include "mbed.h"

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4); 
 
InterruptIn wakeup(p10); 
 
int i = 0;
 
void LEDrun()
{
    unsigned int i, msw=50;
    for (i=1; i<=3; i++)
    {
        myled1 = 1;
        wait_ms(msw);
        myled2 = 1;
        wait_ms(msw);
        myled3 = 1;
        wait_ms(msw);
        myled4 = 1;
        wait_ms(msw);
        myled1 = 0;
        wait_ms(msw);
        myled2 = 0;
        wait_ms(msw);
        myled3 = 0;
        wait_ms(msw);
        myled4 = 0;
        wait_ms(msw);
    } 
}
 
int main() 
{
    wakeup.rise(NULL);  // Setup rising edge interrupt (no handler function needed)
    while (1) 
    {
        deepsleep();  // Deep sleep until external interrupt
        LEDrun(); // We've come out of sleep due to interrupt, so flash some LEDs!
        wait(1);      
    }
}

However - it doesn't seem to wakeup at all. Nothing happens. Has anybody a hint what I am doing wrong? Thanks!

1 Answer

10 years, 7 months ago.

Ah that is where people are getting that wrong piece of code from :P. These days (read: a few years or so), wake.rise(NULL) disables the interrupt. Not exactly what you want. Solution: Attach a function with wake.rise(&yourFunction). The yourFunction doesn't actually need to do anything, it just needs to exist so it enables the interrupt.

Accepted Answer

yupppiieee - works! :-) Thanks!

posted by Martin Heine 07 Apr 2014