Clarification on Retained Memory please!

photon
Tags: #<Tag:0x00007fe21f6cf7d8>

#1

In the Particle reference Docs it is stäted that “If VBAT is floating when powering up for the first time, SRAM remains uninitialized. When using this feature for Backup RAM, it is recommended to have VBAT connected to a 3V3 or a known good power source on system first boot”.

What is meant with “first time” here?
Should I connect VBAT to 3v3 when I setup my Photon for the first time?
Or is it meant that I should connect to 3v3 when loading my application for the first time???

Furthermore: is it possible to use “retained Strings”? (somehow I thought to have read somewhere that this was ot possible, but I cannot find that part in the Reference Docs anymore)


#2

On the Photon only, you may want to connect VBAT to GND if you are not using a coin cell battery or supercap to power VBAT.

The difference is what happens when you power up the Photon the first time. Since there was previously no power, the retained memory contents are uninitialized.

If you connect VBAT to GND, when you first power up the Photon the retained memory will be initialized, either to 0 or to a specific value if the variable has an initializer (usually, see below).

Another technique that I prefer is to not rely on the values being initialized at all, but instead including special values (magic bytes) in retained memory. I use 4 bytes (uint32_t). If the magic bytes are not set, I assume the retained memory is not set and initialize it manually.

There are many more examples here, including how to save strings. You can’t use a String but you can use a character array.


#3

Thanks for te quick response, Rick, but what is “the first time”?
Is that when I take the Photon out of it’s package and power it up for the Setup procedure???


#4

It’s not really first time. It’s any time that power has been completely removed and there was no power on USB, VIN, or VBAT and you want the retained memory to be reinitialized to a known state.


#5

Thanks!