Jason Reiss
/
BackupRegisterExample
Example of using backup registers on mDot
Fork of Dot-Examples by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "mDot.h" 00003 #include "ChannelPlans.h" 00004 00005 static bool deep_sleep = false; 00006 00007 #define CHANNEL_PLAN CP_US915 00008 00009 mDot* dot = NULL; 00010 lora::ChannelPlan* plan = NULL; 00011 00012 Serial pc(USBTX, USBRX); 00013 00014 #if defined(TARGET_XDOT_L151CC) 00015 I2C i2c(I2C_SDA, I2C_SCL); 00016 ISL29011 lux(i2c); 00017 #else 00018 AnalogIn lux(XBEE_AD0); 00019 #endif 00020 00021 int main() { 00022 00023 pc.baud(115200); 00024 00025 mts::MTSLog::setLogLevel(0); 00026 00027 #if CHANNEL_PLAN == CP_US915 00028 plan = new lora::ChannelPlan_US915(); 00029 #elif CHANNEL_PLAN == CP_AU915 00030 plan = new lora::ChannelPlan_AU915(); 00031 #elif CHANNEL_PLAN == CP_EU868 00032 plan = new lora::ChannelPlan_EU868(); 00033 #elif CHANNEL_PLAN == CP_KR920 00034 plan = new lora::ChannelPlan_KR920(); 00035 #elif CHANNEL_PLAN == CP_AS923 00036 plan = new lora::ChannelPlan_AS923(); 00037 #elif CHANNEL_PLAN == CP_AS923_JAPAN 00038 plan = new lora::ChannelPlan_AS923_Japan(); 00039 #elif CHANNEL_PLAN == CP_IN865 00040 plan = new lora::ChannelPlan_IN865(); 00041 #endif 00042 assert(plan); 00043 00044 dot = mDot::getInstance(plan); 00045 assert(dot); 00046 00047 00048 printf("\r\nenter loop*****\r\n"); 00049 00050 while (true) { 00051 int8_t bk_reg = 1; // 0, 1, mDot::UBR0, or mDot::UBR1 00052 uint32_t value; 00053 00054 dot->readUserBackupRegister(bk_reg, value); 00055 00056 printf("initial read value %lu from reg UBR%d\r\n", value, bk_reg); 00057 00058 value = rand(); 00059 00060 printf("save value %lu to reg UBR%d\r\n", value, bk_reg); 00061 00062 dot->writeUserBackupRegister(bk_reg, value); 00063 00064 dot->readUserBackupRegister(bk_reg, value); 00065 00066 printf("after write read value %lu from reg UBR%d\r\n", value, bk_reg); 00067 00068 // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method 00069 //sleep_wake_rtc_only(deep_sleep); 00070 //sleep_wake_interrupt_only(deep_sleep); 00071 printf("sleep 5 seconds\r\n"); 00072 dot->sleep(5, mDot::RTC_ALARM, deep_sleep); 00073 00074 dot->readUserBackupRegister(bk_reg, value); 00075 00076 printf("\r\n********after sleep read value %lu from reg UBR%d\r\n\r\n", value, bk_reg); 00077 00078 } 00079 00080 return 0; 00081 } 00082
Generated on Mon Jul 18 2022 09:47:57 by 1.7.2