Wake-up timer library to wake from deepsleep/power-down

Dependencies:   LPC1114_WakeInterruptIn

Fork of WakeUp by Erik -

Revision:
17:49d9e3a3e904
Parent:
15:b2a710aca356
Child:
20:68f2ee917691
--- a/Device/WakeUp_STM_RTC.cpp	Sun Sep 14 06:45:51 2014 +0000
+++ b/Device/WakeUp_STM_RTC.cpp	Wed Apr 22 20:36:13 2015 +0000
@@ -15,6 +15,9 @@
 #define RTC_IRQ     RTC_IRQn
 #endif
 
+//Disabling the Backup Powerdomain does not seem to work nicely anymore if you want to use other RTC functions afterwards.
+//For now I have disabled it in code, if you find WakeUp increases your powerconsumption, try enabling it again (code is still there, just commented)
+
 FunctionPointer WakeUp::callback;
 
 void WakeUp::set_ms(uint32_t ms)
@@ -24,7 +27,7 @@
         wait_us(250);            //The f401 seems to want a delay after init
     }
     
-    PWR->CR |= PWR_CR_DBP;      //Enable power domain
+    //PWR->CR |= PWR_CR_DBP;      //Enable power domain
     RTC->WPR = 0xCA;            //Disable RTC write protection
     RTC->WPR = 0x53;
     
@@ -33,7 +36,7 @@
     while(!(RTC->ISR & RTC_ISR_ALRAWF));
     
     if (ms == 0) {              //Just disable alarm
-        PWR->CR &= ~PWR_CR_DBP; //Disable power domain
+        //PWR->CR &= ~PWR_CR_DBP; //Disable power domain
         RTC->WPR = 0xFF;        //Enable RTC write protection
         return;
     }
@@ -82,7 +85,7 @@
     RTC->CR |= RTC_CR_ALRAE | RTC_CR_ALRAIE;            //Enable Alarm
     
     RTC->WPR = 0xFF;        //Enable RTC write protection
-    PWR->CR &= ~PWR_CR_DBP; //Disable power domain
+    //PWR->CR &= ~PWR_CR_DBP; //Disable power domain
     
     __enable_irq();         //Alarm is set, so irqs can be enabled again
     
@@ -95,10 +98,14 @@
 void WakeUp::irq_handler(void)
 {
     //Clear RTC + EXTI interrupt flags
-    PWR->CR |= PWR_CR_DBP;      //Enable power domain
+    //PWR->CR |= PWR_CR_DBP;      //Enable power domain
     RTC->ISR &= ~RTC_ISR_ALRAF;
+    RTC->WPR = 0xCA;            //Disable RTC write protection
+    RTC->WPR = 0x53;
+    RTC->CR &= ~RTC_CR_ALRAE;
+    RTC->WPR = 0xFF;        //Enable RTC write protection
     EXTI->PR = EXTI_RTC_LINE;
-    PWR->CR &= ~PWR_CR_DBP;     //Disable power domain 
+    //PWR->CR &= ~PWR_CR_DBP;     //Disable power domain 
     callback.call();
 }