# Battery lasting for rtc and eeprom

**URL:** <https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066>\
**Category:** General\
**Created:** [February 28, 2017, 2:47pm UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066 "2017-02-28T14:47:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suriken](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@Suriken](https://community.particle.io/u/Suriken)\
**Post date:** [February 28, 2017, 2:47pm UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/1 "2017-02-28T14:47:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BulldogLowell](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bulldoglowell/32/4305_2.png) [@BulldogLowell](https://community.particle.io/u/BulldogLowell)\
**Post date:** [February 28, 2017, 4:14pm UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/2 "2017-02-28T16:14:08Z")

</div>

> 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...](https://docs.particle.io/reference/firmware/photon/#backup-ram-sram-)

---

<div class="post-metadata">

**Author:** ![Suriken](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@Suriken](https://community.particle.io/u/Suriken)\
**Post date:** [February 28, 2017, 4:29pm UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/3 "2017-02-28T16:29:49Z")

</div>

Thank you. About hard reset… is it the one produced by reset button?

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [February 28, 2017, 6:51pm UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/4 "2017-02-28T18:51:55Z")

</div>

@Suriken, yes it is. It also includes driving the RST line low which effectively does the same thing.

---

<div class="post-metadata">

**Author:** ![Suriken](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@Suriken](https://community.particle.io/u/Suriken)\
**Post date:** [March 1, 2017, 7:07am UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/5 "2017-03-01T07:07:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 1, 2017, 7:32am UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/6 "2017-03-01T07:32:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Suriken](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@Suriken](https://community.particle.io/u/Suriken)\
**Post date:** [March 1, 2017, 10:31am UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/8 "2017-03-01T10:31:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 1, 2017, 11:00am UTC](https://community.particle.io/t/battery-lasting-for-rtc-and-eeprom/30066/9 "2017-03-01T11:00:08Z")

</div>

Yes, just as the docs about [VBAT](https://docs.particle.io/datasheets/photon-datasheet/#pin-description) and [Backup RAM](https://docs.particle.io/reference/firmware/photon/#backup-ram-sram-) suggest

> [@](#):
>
> VBAT Supply to the internal RTC, backup registers and SRAM when 3V3 is not present (1.65 to 3.6VDC).

> [@](#):
>
> the backup RAM is retained so long as power is provided to VIN or to VBAT. _(ScruffR: "or to 3v3")_  
> In particular this means that the data in backup RAM is retained when:
> 
> - the device goes into deep sleep mode
> - the device is hardware or software reset (while maintaining power)
> - power is removed from VIN but retained on VBAT (which will retain both the backup RAM and the RTC)
> 
> **Note** that if neither VIN nor VBAT _(nor 3v3)_ is powered then the contents of the backup RAM will be lost; for data to be retained, the device needs a power source. For persistent storage of data through a total power loss, _please use the EEPROM_.
