__irq void INT_RtcHandler (void) { RTCICR_bit.RTCICR = 1; // Clear IT flag } |
RTCMR = RTCDR + 5; // Update RTC value to wake up from Deep Sleep mode (5sec just to try) RTCIMSC = 1; // Enable RTC IT PCON_bit.DPDEN = 0; // BOD and WDT configuration in Deep Sleep mode PDSLEEPCFG_bit.BOD_PD = 0; // BOD circuit powered PDSLEEPCFG_bit.WDTOSC_PD = 0; // WDT oscillator powered PDAWAKECFG = PDRUNCFG; // Save Power configuration PDRUNCFG_bit.WDTOSC_PD = 0; // WDT oscillator powered MAINCLKSEL_bit.SEL = 2; // WDT oscillator clock source WDTOSCCTRL_bit.FREQSEL = 1; // FREQSEL : 0,5MHz (errata sheet) WDTOSCCTRL_bit.DIVSEL = 31; //DIVSEL : 64 (errata sheet) // Then reset and set UEN for changes to take effect MAINCLKUEN = 0; MAINCLKUEN = 1; while ((MAINCLKUEN & 1) == 0); // Wait changes to be done // Configure RTC to wake up STARTAPRP1_bit.ARPINT30 = 1; // Rising edge STARTERP1_bit.ERINT30 = 1; // Enable start signal STARTRSRP1CLR_bit.RSRINT30 = 1; // Reset start signal HalIrqInstall(RTC_IRQ, 3); // Enable RTC interrupt (priority 3) SYSAHBCLKCTRL_bit.WDT = 1; // Enable clock for WDT SCR_bit.SLEEPDEEP = 1; __WFI(); |