6 years, 2 months ago.

mDot persistent variables across sleep

Hello everyone –

Does anyone have example code that they can share showing the use of read and write user backup register? I can’t get it to work right.

This isn't working for me:

                    if ((ret = dot->writeUserBackupRegister(0, sleeptime)) != mDot::MDOT_OK){ 
                            pc.printf("Failed to write sleeptime\r\n"); 
                        } else {
                            pc.printf("Wrote sleeptime\r\n"); 
                        }

I’m trying to save my sleep time of dot->sleep(sleep_time, mDot::RTC_ALARM); between sleeps.

1 Answer

6 years, 2 months ago.

I think it is working although your check fails because it is expecting MDOT_OK to be returned.

MDOT_OK is defined as 0 and is equivalent to false. The check is printing failed if NOT 0 is returned. In the success case true will be returned which is definitely not 0.

From mDot.h the backup register functions are declared to return a true or false value https://os.mbed.com/teams/MultiTech/code/libmDot-mbed5/file/mDot.h/

bool writeUserBackupRegister(uint32_t reg, uint32_t data); bool readUserBackupRegister(uint32_t reg, uint32_t& data);