Example of using sleep/deepsleep with the LPC812
After some initial code the device goes into powerdown (deepsleep), or sleep mode. By creating a rising edge on pin D0 (I just use a cable to connect it to Vdd) it will leave sleep, blink blue, and go to sleep again. Aditionally after 10 seconds of sleep it will blink green using the low-power wake-up timer.
Brownout detection and Watchdog timer are disabled since in deepsleep they are the primary power consumers.
main.cpp@1:85ca0ec1e66f, 2013-11-23 (annotated)
- Committer:
- Sissors
- Date:
- Sat Nov 23 11:36:34 2013 +0000
- Revision:
- 1:85ca0ec1e66f
- Parent:
- 0:273b2570ead8
Added wakeup timer.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 0:273b2570ead8 | 1 | #include "mbed.h" |
Sissors | 1:85ca0ec1e66f | 2 | #include "WakeUp.h" |
Sissors | 0:273b2570ead8 | 3 | |
Sissors | 1:85ca0ec1e66f | 4 | DigitalOut led1(LED1); |
Sissors | 1:85ca0ec1e66f | 5 | DigitalOut led2(LED2); |
Sissors | 0:273b2570ead8 | 6 | InterruptIn inter(D0); |
Sissors | 0:273b2570ead8 | 7 | |
Sissors | 0:273b2570ead8 | 8 | |
Sissors | 1:85ca0ec1e66f | 9 | void interirq(void) |
Sissors | 1:85ca0ec1e66f | 10 | { |
Sissors | 1:85ca0ec1e66f | 11 | led1 = 0; |
Sissors | 1:85ca0ec1e66f | 12 | wait(0.2); |
Sissors | 1:85ca0ec1e66f | 13 | led1 = 1; |
Sissors | 1:85ca0ec1e66f | 14 | } |
Sissors | 0:273b2570ead8 | 15 | |
Sissors | 1:85ca0ec1e66f | 16 | void wakeirq(void) |
Sissors | 1:85ca0ec1e66f | 17 | { |
Sissors | 1:85ca0ec1e66f | 18 | led2 = 0; |
Sissors | 1:85ca0ec1e66f | 19 | wait(0.2); |
Sissors | 1:85ca0ec1e66f | 20 | led2 = 1; |
Sissors | 0:273b2570ead8 | 21 | } |
Sissors | 0:273b2570ead8 | 22 | |
Sissors | 1:85ca0ec1e66f | 23 | int main() |
Sissors | 1:85ca0ec1e66f | 24 | { |
Sissors | 1:85ca0ec1e66f | 25 | led1 = 1; |
Sissors | 1:85ca0ec1e66f | 26 | led2 = 1; |
Sissors | 0:273b2570ead8 | 27 | inter.rise(interirq); |
Sissors | 1:85ca0ec1e66f | 28 | WakeUp::calibrate(); |
Sissors | 1:85ca0ec1e66f | 29 | WakeUp::attach(wakeirq); |
Sissors | 1:85ca0ec1e66f | 30 | |
Sissors | 1:85ca0ec1e66f | 31 | |
Sissors | 1:85ca0ec1e66f | 32 | //Disable BOD and WDT (only done to get nice low deepsleep power): |
Sissors | 0:273b2570ead8 | 33 | LPC_SYSCON->PDRUNCFG |= (1<<3) | (1<<6); |
Sissors | 1:85ca0ec1e66f | 34 | |
Sissors | 1:85ca0ec1e66f | 35 | WakeUp::set(10); |
Sissors | 0:273b2570ead8 | 36 | while(1) { |
Sissors | 0:273b2570ead8 | 37 | //sleep(); |
Sissors | 0:273b2570ead8 | 38 | deepsleep(); |
Sissors | 1:85ca0ec1e66f | 39 | WakeUp::set(10); |
Sissors | 0:273b2570ead8 | 40 | } |
Sissors | 0:273b2570ead8 | 41 | } |
Sissors | 1:85ca0ec1e66f | 42 |