readUserBackupRegister
- This topic has 9 replies, 2 voices, and was last updated 7 years, 3 months ago by
Jason Reiss.
-
AuthorPosts
-
January 27, 2018 at 4:20 pm #22483
Pete
ParticipantHello 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.
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.Thanks for any advice. I know C++ only enough to be dangerous.
January 30, 2018 at 6:22 pm #22491Pete
ParticipantAnyone?
This is an mDot, that I’m trying to keep persistent variables across sleep.
January 31, 2018 at 6:53 am #22492Jason Reiss
KeymasterWhat is not working?
sleeptime != sleep_time
January 31, 2018 at 5:34 pm #22495Pete
ParticipantI’m sorry, I was not very clear, and had typos. Both readUserBackRegister and write fail.
Beginning code:
if ((ret = dot->readUserBackupRegister(0, sleeptime)) != mDot::MDOT_OK){ pc.printf("Failed to read - sleeptime is %d\r\n",sleeptime); } else { pc.printf("Read in sleeptime as %d\r\n",sleeptime); } if(sleeptime > 2000) sleeptime = 1; // sleeptime is some crazy number pc.printf("Sleep set for %d Minutes\n\r", sleeptime);
End Code
if ((ret = dot->writeUserBackupRegister(0, sleeptime)) != mDot::MDOT_OK){ pc.printf("Failed to write sleeptime\r\n"); } else { pc.printf("Wrote sleeptime as %d\r\n",sleeptime); }
Output is
Failed to read - sleeptime is 134219489 Sleep set for 1 Minutes . . . Failed to write sleeptime Sleeping 60 seconds or 1 minutes.
-
This reply was modified 7 years, 3 months ago by
Pete.
February 2, 2018 at 6:47 pm #22509Pete
ParticipantAre there no Multitech devs around there that help a guy out?
February 3, 2018 at 12:59 pm #22512Jason Reiss
KeymasterI 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 0 is NOT 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);-
This reply was modified 7 years, 3 months ago by
Jason Reiss.
February 3, 2018 at 2:29 pm #22514Pete
ParticipantThanks for looking at my code snippets, Jason –
I have other code that uses the same format and works fine, so I don’t think it has to do with my check on MDOT_OK. I did change my test to:
if ((ret = dot->readUserBackupRegister(0, sleeptime)) == true)
But no difference.
The problem is that it successfully reads and writes, but the actual data is no good.
When waking from sleep, I get –
Read in sleeptime as 134219489Even though I have written the register to be 1, it still reads as 134219489.
Register 1 is no better, it’s just a 0, and I cannot change it.
February 3, 2018 at 7:14 pm #22515Jason Reiss
KeymasterCan you compile and try this example on your mDot?
https://os.mbed.com/users/jreiss/code/BackupRegisterExample/
February 4, 2018 at 8:53 am #22516Pete
ParticipantHi Jason –
Thanks so much for the example code!
Your code works perfectly for me. With this, I now have a good example, and can work to fix my code.
I really appreciate you taking the time to help this amateur out!
February 4, 2018 at 10:50 am #22517Jason Reiss
KeymasterGlad to help Pete.
If you ever need more timely support, our support portal is also available to customers. support.multitech.com -
This reply was modified 7 years, 3 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.