There have been a number of questions on different forums about waking up from Deep-Sleep mode on the LPC1114 or LPC1343 lately, partially because the current user manual isn't very clear on this (for example, it's not terribly obvious whether a timer is able to run in deep-sleep mode or not). After trying to wrap our head around this ourselves, we ended up contacting NXP directly, who were able to clear the matter up for us. It is indeed possible to wakeup from deep-sleep in software using a timer, though it may not be exactly how you expected.
You enter deep-sleep mode by indicating which peripherals should be turned off, setting up the different registers controlling the sleep modes, and sending the WFI (Wait For Interrupt) command. To exit deep-sleep mode, you simply need to change the state of a pre-configured wakeup pin (0.0..1.0 on the LPC1114 and 0.0..3.3 on the LPC1343), and your device will wakeup (entering the wakeup ISR). That's relatively easy and the manual is clear on that ... what's a lot less clear is how you can wakeup from Deep-Sleep mode purely in SW (or if it's even possible). It is indeed possible, but the only way to do so is with the following steps:
Configuring the LPC1114/LPC1343 to Wakeup from Deep-Sleep
- Before entering deep-sleep, switch the main clock source to WDTOSC (for the lowest possible power consumption)
- Next, find an available wakeup pin with a timer MAT (for example pin 0.1 on the LPC1114 and LPC1343 has CT32B0_MAT2)
- Set the matching timer delay to an appropriate length (for example, a 10s delay on CT32B0)
- Configure the timer's match control register to set the MAT pin (MAT2/0.1 in this case) high on match
- Enable the wakeup interrupt for the MAT pin, and enable the MAT pin as a wakeup source
- Start the timer
- Send the "WFI" command and enter Deep-Sleep mode
What this will do is allow the timer to continue running in deep-sleep using the WDTOSC as a clock source, and when a match occurs it will toggle the MAT pin from low to high, waking the device up. At that point, you will enter the WAKEUP IRQ handler, and you can switch the main clock source back to the internal or external oscillator and adjust the clock accordingly. (For reference sake, keeping a 32-bit timer running in deep-sleep with the WDTOSC at 10kHz consumes about 2uA more than if the device is put in deep-sleep mode with no SW wakeup enabled.)
If this isn't clear, we've added examples of entering and waking up from deep-sleep in both the LPC1114 and LPC1343 Code Base. Both devices behave identically, aside from the smaller number of wakeup pins (13) on the LPC1114 and the difference peripherals that can be disabled in deep-sleep. For an example, see pmuDeepSleep in pmu.c, or have a look at the latest source code on Google Code.
Using the above code, you can enter deep-sleep, and then wakeup after a fixed delay in seconds with the following commands (this assumes that you are using an LPC1343):
uint32_t pmuRegVal;
// Initialise power management
pmuInit();
// Inidicate which peripherals should be disabled in deep-sleep
pmuRegVal = SCB_PDSLEEPCFG_IRCOUT_PD |
SCB_PDSLEEPCFG_IRC_PD |
SCB_PDSLEEPCFG_FLASH_PD |
SCB_PDSLEEPCFG_USBPLL_PD |
SCB_PDSLEEPCFG_SYSPLL_PD |
SCB_PDSLEEPCFG_SYSOSC_PD |
SCB_PDSLEEPCFG_ADC_PD |
SCB_PDSLEEPCFG_BOD_PD;
// Enter deep sleep mode and wakeup after 5 seconds
pmuDeepSleep(pmuRegVal, 5);