![](/media/cache/profiles/f095cedd23b99f1696fc8caecbcf257e.jpg.50x50_q85.jpg)
deep sleep and wake-up. GPIO group interrupt, start logic sample see: http://mbed.org/users/okini3939/notebook/low-power-m0/
main.cpp
- Committer:
- okini3939
- Date:
- 2012-10-15
- Revision:
- 0:ae90ac40c518
- Child:
- 1:d676ec86101e
File content as of revision 0:ae90ac40c518:
#include "mbed.h" DigitalOut myled(LED1); Serial pc(p9, p10); void initStartLogic (unsigned int p0, unsigned int p1) { LPC_SYSCON->SYSAHBCLKCTRL |= (1<<24); LPC_GPIO_GROUP_INT1->PORT_POL[0] = 0; LPC_GPIO_GROUP_INT1->PORT_POL[1] = 0; LPC_GPIO_GROUP_INT1->PORT_ENA[0] = p0; LPC_GPIO_GROUP_INT1->PORT_ENA[1] = p1; LPC_GPIO_GROUP_INT1->CTRL = 0; // Edge, OR, INT LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG; LPC_SYSCON->STARTERP1 = (1<<21); // start logic GROUP1 NVIC_ClearPendingIRQ(GINT1_IRQn); NVIC_EnableIRQ(GINT1_IRQn); } unsigned int setSystemMainClock(unsigned short S) { if ((S & 0x03) == 3) { LPC_SYSCON->PDRUNCFG &= ~(1 << 5); /* Power-up System Osc */ for (int i = 0; i < 200; i++) __NOP(); } LPC_SYSCON->MAINCLKSEL = S; /* Select PLL Clock Output */ LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */ LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */ LPC_SYSCON->MAINCLKUEN = 0x01; while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */ if ((S & 0x03) == 0) { LPC_SYSCON->PDRUNCFG |= (1 << 5); /* Power-down System Osc */ } SystemCoreClockUpdate(); return SystemCoreClock; } unsigned int setSystemFrequency(unsigned short M, unsigned short P) { LPC_SYSCON->SYSPLLCTRL = ((P & 0x03)<<5) | (M & 0x1f); while (!(LPC_SYSCON->SYSPLLSTAT & 0x01)); // Wait Until PLL Locked SystemCoreClockUpdate(); return SystemCoreClock; } void DeepSleep () { SCB->SCR |= (1<<2); __WFI(); } void Sleep () { __WFI(); } extern "C" void GINT1_IRQHandler(void) { LPC_GPIO_GROUP_INT1->CTRL |= (1<<0); NVIC_ClearPendingIRQ(GINT0_IRQn); } int main() { int i; // setSystemFrequency(3, 1); // M, P, 48MHz pc.baud(9600); pc.printf("low power\r\n"); for (i = 0; i < 6; i ++) { myled = !myled; wait(0.5); } initStartLogic((1<<8), 0); loop: pc.printf("enter sleep\r\n"); wait_ms(10); setSystemMainClock(0); DeepSleep(); setSystemMainClock(3); pc.printf("wake up\r\n"); for (i = 0; i < 6; i ++) { myled = !myled; wait(0.5); } goto loop; }