lpcware

Can't wakeup again from Deep Sleep Mode -- LPC1343

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by wsyuen on Wed Sep 21 02:12:14 MST 2011
Dear All,

I used a Timer and several I/O pins as wakeup source in Deep Sleep Mode.
It can be wake-up by Timer in the first time. After that, when it goes to Deep Sleep again, it can't be wake-up by Timer again. Why?
Here are part of my code.
Please help. Thank you very much.


void pmuDeepSleep(uint32_t sleepCtrl, uint32_t wakeupSeconds)
{
  SCB_PDAWAKECFG = SCB_PDRUNCFG;
  sleepCtrl |= (1 << 9) | (1 << 11);
  SCB_PDSLEEPCFG = sleepCtrl;
  SCB_SCR |= SCB_SCR_SLEEPDEEP;

  /* Configure system to run from WDT and set TMR32B0 for wakeup          */
  if (wakeupSeconds > 0)
  {
    // Make sure WDTOSC isn't disabled in PDSLEEPCFG
    SCB_PDSLEEPCFG &= ~(SCB_PDSLEEPCFG_WDTOSC_PD);
    // Disable 32-bit timer 0 if currently in use
    TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_DISABLED;
    // Reconfigure clock to run from WDTOSC
    pmuWDTClockInit();
    /* Enable the clock for CT32B0 */
    SCB_SYSAHBCLKCTRL |= (SCB_SYSAHBCLKCTRL_CT32B0);
    /* Configure 0.1 as Timer0_32 MAT2 */
    IOCON_PIO0_1 &= ~IOCON_PIO0_1_FUNC_MASK;
    IOCON_PIO0_1 |= IOCON_PIO0_1_FUNC_CT32B0_MAT2;
    /* Set appropriate timer delay */
    TMR_TMR32B0MR0 = PMU_WDTCLOCKSPEED_HZ * wakeupSeconds;
    /* Configure match control register to raise an interrupt and reset on MR0 */
    TMR_TMR32B0MCR |= (TMR_TMR32B0MCR_MR0_INT_ENABLED | TMR_TMR32B0MCR_MR0_RESET_ENABLED);
    /* Configure external match register to set 0.1 high on match */
    TMR_TMR32B0EMR &= ~(0xFF<<4);                   // Clear EMR config bits
    TMR_TMR32B0EMR |= TMR_TMR32B0EMR_EMC2_HIGH;     // Set MAT2 (0.1) high on match
    /* Enable wakeup interrupts (any I/O pin can be used as a wakeup source) */
    NVIC_EnableIRQ(WAKEUP1_IRQn);      // P0.1    (CT32B0_MAT2)
    NVIC_EnableIRQ(WAKEUP4_IRQn);    // P0.4
    NVIC_EnableIRQ(WAKEUP5_IRQn);    // P0.5
    NVIC_EnableIRQ(WAKEUP6_IRQn);    // P0.6
    NVIC_EnableIRQ(WAKEUP7_IRQn);    // P0.7
    NVIC_EnableIRQ(WAKEUP14_IRQn);   // P1.2
    NVIC_EnableIRQ(WAKEUP36_IRQn);   // P3.0
    NVIC_EnableIRQ(WAKEUP37_IRQn);   // P3.1
    NVIC_EnableIRQ(WAKEUP38_IRQn);   // P3.2
    NVIC_EnableIRQ(WAKEUP39_IRQn);   // P3.3

    /* Use FALLING EDGE for wakeup detection. PIO3_0 - PIO3_3 */
    SCB_STARTAPRP1 &= !(SCB_STARTAPRP1_APRPIO3_0|SCB_STARTAPRP1_APRPIO3_1|SCB_STARTAPRP1_APRPIO3_2|SCB_STARTAPRP1_APRPIO3_3);
    /* Use FALLING EDGE for wakeup detection. PIO0_4 - PIO0_7, PIO1_2 */
    SCB_STARTAPRP0 &= !(SCB_STARTAPRP0_APRPIO0_4|SCB_STARTAPRP0_APRPIO0_5|SCB_STARTAPRP0_APRPIO0_6|SCB_STARTAPRP0_APRPIO0_7);
    SCB_STARTAPRP0 |= SCB_STARTAPRP0_APRPIO1_2; // Use RISING EDGE for wakeup detection
    /* Use RISING EDGE for wakeup detection. */
    SCB_STARTAPRP0 |= SCB_STARTAPRP0_APRPIO0_1;

    /* Clear all wakeup sources */
    SCB_STARTRSRP0CLR = SCB_STARTRSRP0CLR_MASK;
    /* Clear all wakeup sources */
    SCB_STARTRSRP1CLR = SCB_STARTRSRP1CLR_MASK;
    /* Enable PIO0_4 - PIO0_7, PIO1_0, PIO1_2 as wakeup source. */
    SCB_STARTERP0 = (SCB_STARTERP0_ERPIO0_4|SCB_STARTERP0_ERPIO0_5|SCB_STARTERP0_ERPIO0_6|SCB_STARTERP0_ERPIO0_7|SCB_STARTERP0_ERPIO1_2|SCB_STARTERP0_ERPIO0_1);
    /* Enable PIO3_0 - PIO3_3 as wakeup source. */
    SCB_STARTERP1 = (SCB_STARTERP1_ERPIO3_0|SCB_STARTERP1_ERPIO3_1|SCB_STARTERP1_ERPIO3_2|SCB_STARTERP1_ERPIO3_3);

    /* Start the timer */
    TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_ENABLED;
  }
   __WFI();
  return;
}



void WAKEUP_IRQHandler(void)
{
  uint32_t regVal;
  // Disable the deep sleep timer
  TMR_TMR32B0TCR = TMR_TMR32B0TCR_COUNTERENABLE_DISABLED;
  /* This handler takes care of all the port pins if they
  are configured as wakeup source. */
  regVal = SCB_STARTSRP0;
  if (regVal != 0)
  {
    SCB_STARTRSRP0CLR = regVal;
  }
  regVal = SCB_STARTSRP1;
  if (regVal != 0)
  {
    SCB_STARTRSRP1CLR = regVal;
  }
  // Reconfigure system clock/PLL
  cpuPllSetup(CPU_MULTIPLIER_1);
  // Reconfigure CT32B0
  timer32Init(0, TIMER32_DEFAULTINTERVAL);
  timer32Enable(0);
  return;
}



       pmuRegVal = SCB_PDSLEEPCFG_IRCOUT_PD | SCB_PDSLEEPCFG_IRC_PD | SCB_PDSLEEPCFG_FLASH_PD | SCB_PDSLEEPCFG_USBPLL_PD | SCB_PDSLEEPCFG_USBPAD_PD | SCB_PDSLEEPCFG_SYSPLL_PD | SCB_PDSLEEPCFG_SYSOSC_PD | SCB_PDSLEEPCFG_ADC_PD | SCB_PDSLEEPCFG_BOD_PD;
        // Enter deep sleep mode and wakeup after 10 seconds
        pmuDeepSleep(pmuRegVal, 10);

Outcomes