Detect in software if VBAT / battery is available

Is there a way to detect if a battery (3.3V) is available from the firmware?

I’ve read that SRAM only initialises when a battery is present (eg. VBAT not floating). So there is some way to detect if the SRAM is active (or battery is present?).

https://docs.particle.io/reference/firmware/photon/#enabling-backup-ram-sram-

I’m creating a device and sometimes I’d like to add a battery and sometimes not. I don’t want to change the hardware (connect VBAT to ground, if no battery is present).

I’m also curious what happens if the battery connected to VBAT runs empty.

What device are you thinking of?
Electrons always have 3.3V present as long a LiPo is attached.

But I don’t know of such a logic. Hence I’d try to guess by the contents of my SRAM/RTC data - e.g. magic number or checksum.

Sorry, I’m working with the Photon.

With some products I’d like to use an alarm function, so it’s beneficial to add the battery to keep the RTC running.
However with others I was thinking to remove it. I’d like to detect in the setup/startup what is available to walk through the correct states.

I suppose the contents of SRAM are random? When not initialised? So in theory this could be equal to my magic number, even when not initialised?

That’d be highly unlikely and when checking the RTC even more so :wink:

1 Like

@kasper, just a note. STM recommends connecting Vbat to Vcc when not in use. You may want to consider a cut-away PCB jumper to simplify external battery selection.

Thanks, good to know that. I suppose that is the reason that the Electron has a 0 ohm resistor between VBAT and 3.3Volt?

Why is it advised to connect it to ground when you use extra RAM (instead of backup RAM) in the documentation?

https://docs.particle.io/reference/firmware/photon/#backup-ram-sram-

When using this feature for Extra RAM, it is recommended to jumper VBAT to GND to ensure it always initializes on system first boot.

@kasper, that statement is misleading IMO. STMicro recommends placing a cap on Vbat to slow the power-up rise time on the pin in order to satisfy the boot requirements.

Do you have a link to the right documentation of STMicro?

This is my circuit right now (see image below). I can connect VBAT through the diode (or without), I’ve mainly put it in place as a charging circuit for a rechargeable cell. However non-rechargeable might do as well (I think a CR2032 will last for 5 years isn’t it)?

@kasper, you may need a second diode if you put a regular battery. Otherwise, you’ll get current flowing to the battery when it’s voltage drops.

From this app note:

If no external battery is used in the application, it is highly recommended to connect VBAT externally to VDD with a 100 nF decoupling capacitor.

Vbat consumption with RTC and back SRAM will be around 7uA.

But why 0 ohm is used on the Electron then (instead of a 100nF capacitor)?
And why no cap by default on the Photon?

@kasper, the Vdd line on both the Photon and Electron are already decoupled (also physically close) so no need to decouple Vbat as well. The zero ohm (as in jumper not capacitor) on the Electron is so you can disconnect Vbat from Vdd to power it separately.

1 Like

Ok. I’m using the Photon (and not P0/P1), so that means I don’t have to do anything.

I don’t get the 2nd diode part:

@kasper, you may need a second diode if you put a regular battery. Otherwise, you’ll get current flowing to the battery when it’s voltage drops.

If I omit D130 and put 0 ohm in place of the 1K, my circuit will be good for a regular battery?
Or is it smart to remove C129 then as well (and only put that as decoupling when no battery is added?).

@kasper, you can’t have the battery and the diode in place at the same time so yes, you proposed circuit would be fine. C129 is not required since the photon already as adequate decoupling near Vdd and Vbat. Most configurations I have seen use a jumper (pcb trace or otherwise) to select between a Vdd connection or a battery.

@peekay123
Just wondering. Will the VBAT current draw be less if I leave retained memory off? Was the 7uA you mentioned including both SRAM and RTC?

I’ve read this in the docs.

Backup RAM is disabled by default, since it does require some maintenance power which may not be desired on some low-powered projects. Backup RAM consumes roughly 5uA or less on VIN and 9uA or less on VBAT.

I suppose that when not using SRAM power on VBAT is only used to keep the RTC running?

@kasper, if retained RAM is not enabled, Vbat will draw less current for sure.

1 Like