Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retained variables are not persisting, even without reset or deep sleep. #661

Closed
technobly opened this issue Oct 3, 2015 · 6 comments

Comments

@technobly
Copy link
Member

commented Oct 3, 2015

Please see:
https://community.particle.io/t/backup-ram-not-working/16179

Just to confirm, is it correct that retained variables should come up as the last written value after a reset or deep sleep event, and not be re-initialized if declared and initialized globally? So in the first two posts of the above thread, we have:

retained int saveValue = 10;

If the last written state is 500 lets say, after reset it would still be 500, yeah?

@technobly technobly added the bug label Oct 3, 2015

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2015

Strange. I woke up thinking about this and then remembered that the docs don't include the command to enable retained variables.

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2015

Docs updated.

@m-mcgowan m-mcgowan closed this Oct 3, 2015

@technobly

This comment has been minimized.

Copy link
Member Author

commented Oct 3, 2015

Is there a reason it's not always enabled? Since it has a keyword it's pretty unique.

@technobly

This comment has been minimized.

Copy link
Member Author

commented Oct 3, 2015

I just tested with the enable command and now retained seems to work just like normal variables when powered, but if I reset when I'm in the 5 second delay it comes up setting the value to 10 again, instead of 15. If I don't initialize the value, it still comes up as 0 instead of 15.

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

retained int saveValue = 10;

void setup() {
    Serial.begin(9600);
}

void loop() {
        Serial.println(saveValue);
        saveValue = 15;
        Serial.println(saveValue);
        Serial.println(saveValue);
        delay(5000);
}

@technobly technobly reopened this Oct 3, 2015

@technobly

This comment has been minimized.

Copy link
Member Author

commented Oct 3, 2015

Ok figured this out... thought it was ok to hard reset it (pushing the reset button) but it only retains memory with a soft reset, E.g., System.reset();

I'll update the docs with that clarification ;-)

Edit: docs updated.

@technobly technobly closed this Oct 3, 2015

@technobly

This comment has been minimized.

Copy link
Member Author

commented Oct 4, 2015

Ahh, so much confuse... there was an issue with how SRAM was initialized which led to much confusion. Fixed with this PR: #664

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.