Demo of working sleep and deepsleep commands. mbed's version currently does not

Dependencies:   mbed

Fork of DipCortex-SleepyTime by Carl - SolderSplash Labs

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalIn Button(P0_1);
00004 InterruptIn ButtonIrq(P0_1); 
00005 
00006 DigitalOut Led2(P1_22);
00007 
00008 void sleep_normal ( void )
00009 {
00010     // PCON[PD] set to sleep
00011     LPC_PMU->PCON = 0x0;
00012     
00013     // SRC[SLEEPDEEP] set to 0 = sleep
00014     SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
00015     
00016     // wait for interrupt
00017     __WFI();
00018 }
00019 
00020 // Section 3.9.4 of the LPC11U24 User Manual
00021 void sleep_deep ( void )
00022 {
00023 // PCON[PD] set to deepsleep
00024     LPC_PMU->PCON = 0x1;
00025     
00026     // SRC[SLEEPDEEP] set to 1 = deep sleep
00027     SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
00028     
00029     // Power up everything after powerdown
00030     LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800;
00031     
00032     // wait for interrupt
00033     __WFI();
00034 }
00035 
00036 void ButtonPressed ( void )
00037 {
00038     // Wake up ..
00039     Led2 = !Led2;
00040 }
00041 
00042 int main() 
00043 {
00044     Led2 = 1;
00045     Button.mode(PullUp);
00046     ButtonIrq.fall(ButtonPressed);
00047     
00048     while(1) 
00049     {
00050         // All I do is sleep
00051         //sleep_normal();
00052         sleep_deep();
00053     }
00054 }