readUserBackupRegister

Home Forums mDot/xDot readUserBackupRegister

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #22483
    Pete
    Participant

    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.

    
                        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.

    #22491
    Pete
    Participant

    Anyone?

    This is an mDot, that I’m trying to keep persistent variables across sleep.

    #22492
    Jason Reiss
    Keymaster

    What is not working?

    sleeptime != sleep_time

    #22495
    Pete
    Participant

    I’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 6 years, 2 months ago by Pete.
    #22509
    Pete
    Participant

    Are there no Multitech devs around there that help a guy out?

    #22512
    Jason Reiss
    Keymaster

    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 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 6 years, 2 months ago by Jason Reiss.
    #22514
    Pete
    Participant

    Thanks 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 134219489

    Even 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.

    #22515
    Jason Reiss
    Keymaster

    Can you compile and try this example on your mDot?

    https://os.mbed.com/users/jreiss/code/BackupRegisterExample/

    #22516
    Pete
    Participant

    Hi 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!

    #22517
    Jason Reiss
    Keymaster

    Glad to help Pete.
    If you ever need more timely support, our support portal is also available to customers. support.multitech.com

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.