With older Arduinos I am accustomed to using a DS3231 for clock functions, and these have a VBAT pin to maintain time when the Arduino is powered off. We just run a clock setter sketch when changing time zones or at the beginning of a project and the clock is accurate enough over multiple weeks.
Since the Nano ESP32 has a built-in clock, I hope to get the same functionality without buying an external clock for each project. How can I create the equivalent situation of a battery connected to the VBAT pin?
I am picturing a coin cell battery connected to VIN with a diode to prevent reverse current flow. Do I also have to put the system in deep sleep before the external power is removed? Can that be automated during the moments between when a power cable is unplugged and everything stops? I'm just guessing here, hoping someone will set me straight.
Or should I keep buying external clocks and spend my energy elsewhere?
Please don't tell me "just connect to the internet on boot". The projects I build are used by students in remote locations with no internet or cell service, and their puny grant funding won't cover a satellite solution. Power may be coming from an unreliable wall outlet or a boat's generator, so needing clock backup power is a real issue.
Thanks.