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?).
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.
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?
@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.
@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, 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.
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.
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?