I want to create a pcb for a product soon and doing some tests I found that rtc and eeprom values are lost when I unplug power ( I think I read some time ago but I didn’t remember it).
I was considering an i2c eeprom and a rechargeable coin battery for rtc in case the users were not using wifi.
But I read that rtc and eeprom storage consume just 4uA. When the power is on, battery is not discharged, is it?
So, a 80mA battery could last for more than 3-4 years in good conditions. I think this is more than ok for me, the user could remove the case and change the coin cell if needed in some years.
Is this correct? Battery connected to Vbat is not used when power Vin is in use?
The EEPROM functions can be used to store small amounts of data in Flash that will persist even after the device resets after a deep sleep or is powered off.
you may be thinking about Retained Variables:
A retained variable is similar to a regular variable, with some key differences:
it is stored in backup RAM - no space is used in regular RAM
instead of being initialized on each program start, retained variables are initialized when the device is first powered on (with VIN, from being powered off with VIN and VBAT completely removed). When the device is powered on, the system takes care of setting these variables to their initial values. lastTemperature and numberOfPresses would be initialized to 0, while numberOfTriesRemaining would be initialized to 10.
the last value set on the variable is retained as long as the device is powered from VIN or VBAT and is not hard reset.
retained variables can be updated freely just as with regular RAM variables and operate just as fast as regular RAM variables.
You are correct regarding RTC... but it is all in the docs...
In this case I need to include an external eeprom and a RTC because my current design has an external WDT in case something goes wrong and the execution enters in an infinite loop, reset the whole system and start again.
RTC and and retained varaiables will not get lost when hitting RESET or pulling RST low (which is what your ext WDT should do instead of depowering the device).
And the internal EEPROM will not even be erased when the device is depowered.
If you attach a coin cell to VBAT you can even depower the core device and RTC and retained variables will still be kept valid.
RTC means real time clock. It is useful to keep datetime on a device without internet. I use some alarms on my devices and sometimes they don’t have wifi available.
Thank you @ScruffR, then a simple coin cell will be ok.