8 years, 2 months ago.

Wake up from Power-Down mode

I have make my mbed NXP LPC 1768 enter Power-Down mode, and I have set up an real time clock (RTC) interrupt and attempted to use this to wake my board up. However, the ISR is never called, which means the interrupt is never generated. Any clue why this is happening? Any help is appreciated. Please refer to my code below.

main.cpp

#include "mbed.h"
#include "PowerControl.h"
#include "RTC.h"

DigitalOut leds[] = {DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)}; // put each LED object into an array, easier to access

void ISR(void){
    DigitalOut led = DigitalOut(LED4);
    led = 1;
    
    leds[2] = !leds[2];
    if(! (LPC_SC->PCON & 0x400) )
        leds[1] = !leds[1];
 }
 
 
int main() {
    set_time(1455622440); // Tue, 16 Feb 2016 11:34:00 GMT
    //set up real-time clock(RTC) interrupt
    tm t = RTC::getDefaultTM();
    t.tm_sec = 3; //when the second is 3 for the real time, once every minute
 
    RTC::alarm(&ISR, t);

    while (true) {
       leds[0] = !leds[0];
       wait_ms(1000);
       PowerDown();
    }
}

Note: 1) I have used the "RTC.h" public library to set up the RTC alarm interrupt. Don't know too much about the implementation of it

2) The way I make my board to enter power-down mode is using a function from the "PowerControl.h". I have double checked the source code for that function; it is indeed setting bits at the appropriate registers according to the user manual. i.e.

snippet in "PowerControl.h

//System Control Register
// bit 2: Deep Sleep
#define LPC1768_SCR_SLEEPDEEP       0x4


//Power Control Register
// bit 0: Power mode control bit 0 (power-down mode)
#define LPC1768_PCON_PM0            0x1
// bit 1: Power mode control bit 1 (deep power-down mode)
#define LPC1768_PCON_PM1            0x2

//"Power-Down" Mode
inline void PowerDown(void)
{
   SCB->SCR |= LPC1768_SCR_SLEEPDEEP;
   LPC_SC->PCON &= ~LPC1768_PCON_PM1;
   LPC_SC->PCON |= LPC1768_PCON_PM0;
   __WFI();
   //reset back to normal
  LPC_SC->PCON &= ~(LPC1768_PCON_PM1 | LPC1768_PCON_PM0);
}

Question relating to:

Enter power-down mode, but couldn't wake it up using an interrupt from a real time clock (RTC) interrupt Control;, Power, RTC

How do I exit the debug mode? If I exit debug mode, will I be able to wake up the board from its sleepmode/ power-down mode ?

posted by Weidong Guo 21 Feb 2016

1 Answer

8 years, 2 months ago.

Are you using a standalone LPC1768 board or the mbed LPC1768 board. In case you use the mbed one: It is not capable of leaving powerdown mode. The issue is that the interface chip, which does nice things such as the LocalFileSystem, which is also in hindsight a bad idea to implement it like it was implemented, keeps the LPC1768 in debug mode. And M3s+M4s cannot wake from deepsleep/powerdown modes when in debug mode.

Considering the overall current consumption of the board is so high powerdown mode makes little sense anyway, there is little lost here. (The bigger problem then is the horrible LPC11u24 deepsleep implementation they refuse to fix or have fixed by anyone else). If you are using a standalone LPC1768 board the story is different. In that case I would start by using an InterruptIn to try to wake from powerdown.

1) mbed LPC 1768. By the way, because I couldn't get into power-down mode, I tried simply sleep mode. I call sleep() or WFX(), nothing happens. The program continues running when I didn't set up an interrupt.

2) How can I not enter debug mode? Is it by default in debug mode?

posted by Weidong Guo 18 Feb 2016

Well then indeed it will never wake from powerdown mode. Sleep mode should work properly, unless another interrupt wakes it up.

posted by Erik - 18 Feb 2016

For sleep mode, my code is as simple as this. But it didn't stop the program at all. Keep blinking LED

int main() {
 

    while (true) {
       leds[0] = !leds[0];
       wait_ms(1000);
       Sleep();
    }
}

Furthermore, Can a board in deep-sleep mode be waken up ? I tried again using RTC alarm interrupt; it's not waken up.

posted by Weidong Guo 18 Feb 2016

Why is your sleep with a capital s?

And as I write before, no the mbed lpc1768 board cannot wake from deep sleep or power down. This is due to how the board is designed and an arm limitation

posted by Erik - 18 Feb 2016

The implementation of Sleep is from "PowerControl.h", which is

//"Sleep Mode" (WFI).
inline void Sleep(void)
{
    __WFI();
}

Nonetheless, I have replace Sleep() with sleep(); it's not working either. Below is the entire program:

main.cpp

#include "mbed.h"
#include "PowerControl.h"
#include "RTC.h"
DigitalOut leds[] = {DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)}; // put each LED object into an array, easier to access

int main() {
    while (true) {
       leds[0] = !leds[0];
       wait_ms(1000);
       sleep();
    }
}
posted by Weidong Guo 18 Feb 2016

How do I exit the debug mode? If I exit debug mode, will I be able to wake up the board from its deep-sleep mode/ power-down mode ?

posted by Weidong Guo 21 Feb 2016

You can't on the mbed lpc1768 board. I tried pretty much everything, you need a different board.

posted by Erik - 22 Feb 2016