Example of using backup registers on mDot

Dependencies:   libmDot-mbed5

Fork of Dot-Examples by MultiTech

Committer:
jreiss
Date:
Sun Feb 04 01:12:04 2018 +0000
Revision:
26:99458ed6fd31
simplify example;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jreiss 26:99458ed6fd31 1 #include "mbed.h"
jreiss 26:99458ed6fd31 2 #include "mDot.h"
jreiss 26:99458ed6fd31 3 #include "ChannelPlans.h"
jreiss 26:99458ed6fd31 4
jreiss 26:99458ed6fd31 5 static bool deep_sleep = false;
jreiss 26:99458ed6fd31 6
jreiss 26:99458ed6fd31 7 #define CHANNEL_PLAN CP_US915
jreiss 26:99458ed6fd31 8
jreiss 26:99458ed6fd31 9 mDot* dot = NULL;
jreiss 26:99458ed6fd31 10 lora::ChannelPlan* plan = NULL;
jreiss 26:99458ed6fd31 11
jreiss 26:99458ed6fd31 12 Serial pc(USBTX, USBRX);
jreiss 26:99458ed6fd31 13
jreiss 26:99458ed6fd31 14 #if defined(TARGET_XDOT_L151CC)
jreiss 26:99458ed6fd31 15 I2C i2c(I2C_SDA, I2C_SCL);
jreiss 26:99458ed6fd31 16 ISL29011 lux(i2c);
jreiss 26:99458ed6fd31 17 #else
jreiss 26:99458ed6fd31 18 AnalogIn lux(XBEE_AD0);
jreiss 26:99458ed6fd31 19 #endif
jreiss 26:99458ed6fd31 20
jreiss 26:99458ed6fd31 21 int main() {
jreiss 26:99458ed6fd31 22
jreiss 26:99458ed6fd31 23 pc.baud(115200);
jreiss 26:99458ed6fd31 24
jreiss 26:99458ed6fd31 25 mts::MTSLog::setLogLevel(0);
jreiss 26:99458ed6fd31 26
jreiss 26:99458ed6fd31 27 #if CHANNEL_PLAN == CP_US915
jreiss 26:99458ed6fd31 28 plan = new lora::ChannelPlan_US915();
jreiss 26:99458ed6fd31 29 #elif CHANNEL_PLAN == CP_AU915
jreiss 26:99458ed6fd31 30 plan = new lora::ChannelPlan_AU915();
jreiss 26:99458ed6fd31 31 #elif CHANNEL_PLAN == CP_EU868
jreiss 26:99458ed6fd31 32 plan = new lora::ChannelPlan_EU868();
jreiss 26:99458ed6fd31 33 #elif CHANNEL_PLAN == CP_KR920
jreiss 26:99458ed6fd31 34 plan = new lora::ChannelPlan_KR920();
jreiss 26:99458ed6fd31 35 #elif CHANNEL_PLAN == CP_AS923
jreiss 26:99458ed6fd31 36 plan = new lora::ChannelPlan_AS923();
jreiss 26:99458ed6fd31 37 #elif CHANNEL_PLAN == CP_AS923_JAPAN
jreiss 26:99458ed6fd31 38 plan = new lora::ChannelPlan_AS923_Japan();
jreiss 26:99458ed6fd31 39 #elif CHANNEL_PLAN == CP_IN865
jreiss 26:99458ed6fd31 40 plan = new lora::ChannelPlan_IN865();
jreiss 26:99458ed6fd31 41 #endif
jreiss 26:99458ed6fd31 42 assert(plan);
jreiss 26:99458ed6fd31 43
jreiss 26:99458ed6fd31 44 dot = mDot::getInstance(plan);
jreiss 26:99458ed6fd31 45 assert(dot);
jreiss 26:99458ed6fd31 46
jreiss 26:99458ed6fd31 47
jreiss 26:99458ed6fd31 48 printf("\r\nenter loop*****\r\n");
jreiss 26:99458ed6fd31 49
jreiss 26:99458ed6fd31 50 while (true) {
jreiss 26:99458ed6fd31 51 int8_t bk_reg = 1; // 0, 1, mDot::UBR0, or mDot::UBR1
jreiss 26:99458ed6fd31 52 uint32_t value;
jreiss 26:99458ed6fd31 53
jreiss 26:99458ed6fd31 54 dot->readUserBackupRegister(bk_reg, value);
jreiss 26:99458ed6fd31 55
jreiss 26:99458ed6fd31 56 printf("initial read value %lu from reg UBR%d\r\n", value, bk_reg);
jreiss 26:99458ed6fd31 57
jreiss 26:99458ed6fd31 58 value = rand();
jreiss 26:99458ed6fd31 59
jreiss 26:99458ed6fd31 60 printf("save value %lu to reg UBR%d\r\n", value, bk_reg);
jreiss 26:99458ed6fd31 61
jreiss 26:99458ed6fd31 62 dot->writeUserBackupRegister(bk_reg, value);
jreiss 26:99458ed6fd31 63
jreiss 26:99458ed6fd31 64 dot->readUserBackupRegister(bk_reg, value);
jreiss 26:99458ed6fd31 65
jreiss 26:99458ed6fd31 66 printf("after write read value %lu from reg UBR%d\r\n", value, bk_reg);
jreiss 26:99458ed6fd31 67
jreiss 26:99458ed6fd31 68 // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method
jreiss 26:99458ed6fd31 69 //sleep_wake_rtc_only(deep_sleep);
jreiss 26:99458ed6fd31 70 //sleep_wake_interrupt_only(deep_sleep);
jreiss 26:99458ed6fd31 71 printf("sleep 5 seconds\r\n");
jreiss 26:99458ed6fd31 72 dot->sleep(5, mDot::RTC_ALARM, deep_sleep);
jreiss 26:99458ed6fd31 73
jreiss 26:99458ed6fd31 74 dot->readUserBackupRegister(bk_reg, value);
jreiss 26:99458ed6fd31 75
jreiss 26:99458ed6fd31 76 printf("\r\n********after sleep read value %lu from reg UBR%d\r\n\r\n", value, bk_reg);
jreiss 26:99458ed6fd31 77
jreiss 26:99458ed6fd31 78 }
jreiss 26:99458ed6fd31 79
jreiss 26:99458ed6fd31 80 return 0;
jreiss 26:99458ed6fd31 81 }
jreiss 26:99458ed6fd31 82