LP Transmitter Wakeup
Dependencies: max32630fthr USBDevice
main.cpp
- Committer:
- MI
- Date:
- 2018-01-24
- Revision:
- 1:8834bc22c2e7
- Parent:
- 0:41ed595f83f5
- Child:
- 2:33b3b46a9c0d
File content as of revision 1:8834bc22c2e7:
#include "mbed.h" #include "max32630fthr.h" #include "mxc_config.h" #include "lp.h" #include "gpio.h" #include "rtc.h" #include "MAX14690.h" DigitalOut rLED(LED1); DigitalOut gLED(LED2); DigitalOut bLED(LED3); DigitalIn sw1(SW1); // ***************************************************************************** void RTC_Setup() { rtc_cfg_t RTCconfig; RTCconfig.compareCount[0] = 1;//1 second timer RTCconfig.compareCount[1] = 10;//10 second timer RTCconfig.prescaler = RTC_PRESCALE_DIV_2_12; //1Hz clock RTCconfig.prescalerMask = RTC_PRESCALE_DIV_2_12;//used for prescaler compare RTCconfig.snoozeCount = 0; RTCconfig.snoozeMode = RTC_SNOOZE_DISABLE; RTC_Init(&RTCconfig); RTC_Start(); } /******************************************************************************/ int main(void) { MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); //check if starting at main because of LP0 wake-up if(LP_IsLP0WakeUp()) { } else { //We did not wake up from sleep and this is first power-on //Only configure RTC the first time around RTC_Setup(); } gLED = LED_ON; rLED = LED_ON; bLED = LED_ON; while(1) { //hold down switch 1 to prevent the microcontroller from going into LP0 while(sw1 == 0); //keep LED on long enough to see it! wait_ms(100); gLED = LED_OFF; rLED = LED_OFF; bLED = LED_OFF; //disable unused PMIC rails to minimize power consumption pegasus.max14690.ldo2SetMode(MAX14690::LDO_DISABLED); pegasus.max14690.ldo3SetMode(MAX14690::LDO_DISABLED); //Clear existing wake-up config LP_ClearWakeUpConfig(); //Clear any event flags LP_ClearWakeUpFlags(); //configure wake-up on RTC compare 0 //LP_ConfigRTCWakeUp(enable compare 0, enable compare 1, set prescale, set rollover) LP_ConfigRTCWakeUp(1, 0, 0, 0); //read the current RTC timer and add 5 seconds to it uint32_t cmp = RTC_GetCount() + 5; //set RTC to generate an interrupt 5 seconds from current value RTC_SetCompare(0,cmp); //clear comparison flag in the RTC registers RTC_ClearFlags(MXC_F_RTC_FLAGS_COMP0); LP_EnterLP0(); //firmware will reset with no prior knowledge on wake-up } }