The data sheet is not very clear about the "key" pin. An obvious gap is the multiplexing of the flashlight LED and the on/off function on the same pin. In the application circuit, a parallel circuit of a high side driven high current LED circuit (with a very low 20 ohm limiting resistor), and a key in series with a 10k ohm resistor is shown. It's not easily reconcilable with the rest of the document. For example, the other key circuit illustrated, is a simple key pin to ground arrangement. Consider, what happens when a high side driver is directly grounded and enabled (flashlight on). If the flashlight is turned on by enabling the high side driver, how could the key switch be sensed, since the pin is bidirectional? The document makes no attempt to clear up the mystery. So it is hard to know exactly how it functions. As far as I can see, there is no other place in the document where it's addressed.
There is a paragraph, a verbal description rather than timing diagram, concerning the pin. It seems to describe the behaviour without flashlight, except for the statement that it turns off with everything else.
I mention the flashlight driver, only because it has the potential for creating a short circuit through the key pin if the flashlight is enabled and the pin is simultaneously grounded.
That could impact how you would design a safe drive circuit for it. The flashlight is enabled by two short presses, so you also have to avoid doing that. An external MOSFET or the DS3231 output could be damaged by that kind of current.
It actually makes me a little mad, that manufacturers can get away with this kind of vague crap.
aarg, thank you for your analysis. I did not notice it. You are absolutely right.
So, rather than "hacking" the KEY pin, what about placing two FET at the level of current sources: at VIN (pin 1) and at BAT (pin 6) so that the DS3231 can directly cut/open the current? If ok, do you have a suggestion about the schematics? I'm not expert at electronics.
This is one of those single-chip power pack implementations that is supposed to charge the battery at up to 4.2V or boost the battery voltage to 5V, all with a single inductor. But it's not clear if it can behave like a UPS, and supply 5V to the load while charging the battery. Presumably it can.
The other issue is that these power pack chips "feature" automatic shutdown when the load current drops below a certain level. It appears to be 45mA in this case. You will need your Arduino to always draw more current than that. Otherwise the power pack will shut down power.
But if you insist on using this kind of system, it may be possible for the alarm to bring the Key pin low for the right time by using an R/C network of some kind. Do we know anything about the state of the Key pin? The schematic shows a 10K series resistor to the push button. Does that mean the Key pin has an internal pullup resistor? If it does, then perhaps using a capacitor in series would let the alarm initially bring Key low, and then it would go back high as the capacitor recharges even though INT/SQW is still low.
Then on the shutdown issue, the Arduino will have to participate in some way because the shutdown alarm will have to be cleared by reseting that flag. If the alarm pin is also connected to the Arduino, then the Arduino could reset the alarm in less than 30ms, so Key would ignore the initial low, and then reduce its current to less than 45mA, and just let the power pack shut everything down.
Well, these are just random thoughts. Maybe something will be usable, or will suggest alternatives.
thank you ShermanP for the advice. I'll take a closer look to your advices.
Do you know alternative to this IC? at TI or other big electronic companies?
To what register ? I have vague memory to have read once somewhere that you don’t have control on that INT pin, you can enable or disable alarms or enable disable the square wave
(My recollection might be wrong though)
"Bit 1: Alarm 2 Flag (A2F). A logic 1 in the alarm 2 flag
bit indicates that the time matched the alarm 2 regis-
ters. If the A2IE bit is logic 1 and the INTCN bit is set to
logic 1, the INT/SQW pin is also asserted. A2F is
cleared when written to logic 0. This bit can only be
written to logic 0. Attempting to write to logic 1 leaves
the value unchanged."
Can you tell us more about your project? Do you need to power up the Arduino at a particular time of day? And what about shutting it down? Does that need to happen at a particular time also?
I don't know of a single IC that does both battery charging and boost conversion. For a single cell, there are low-cost modules that include the TP4056 charger and the MT3608 boost converter, but I have my doubts about them. And I don't think they have a simple way to turn them on and off. TI might have a single chip solution, but I'm just not familiar with their charger ICs.
my project uses a battery powered arduino (ESP32) that needs to be wakeup at certain moments of the day and then shut down (by itself) when the task is finished or by timeout (by external RTC).
The Wakeup time and the shut down time is not know in advance, it is decided day to day by the user. The arduino takes the user defined times from a webserver.
Unless there is a lot of hardware attached, a common method is to run the MCU directly from the battery, not via a converter. Then it always has power available and can just go to sleep when it's not required to do any work. I haven't explored that aspect myself yet (although I have begun playing with ESP32 a lot), but I think sleep modes are well supported on that chip.
Ralph Bacon has posted a new video on ESP32 deep sleep. It may be possible to leave the power on, but put the ESP32 into deep sleep, and wake it up using the built in RTC. I don't think you can power the built-in RTC separately with a coin cell, and power down the rest of the ESP32. I don't think it would wake up if it's powered down. But deep sleep current might be low enough to make things work, and then you wouldn't need a separate DS3231, and wouldn't need to switch off the power.
But the ESP32 is a 3.3V device. Do you not need 5V for anything else? If not, then using a 3.3V linear regulator might make sense. At very low deep sleep currents, a linear regulator would probably be more efficient than a switching regulator, and it sounds like your device will be sleeping most of the time. I don't think you can power an ESP32 directly from a Li-ion cell, which can be as high as 4.2V. You can do that with an ATMega328P, but not an ESP32.
I'll attach a circuit that might be used as a UPS. It uses the TP4056 charger and a load sharing circuit (aka power path) that allows the 5V USB input to directly power the load when it is present rather than going through the charger. The schematic shows a boost converter to 5V, but a linear 3.3V regulator could be used instead.
Do you have a feel for the maximum current draw the project will need?
Actually, you could power the ESP32 directly using LiFePO4 batteries, which have a maximum 3.6V. Probably 2 AAs in parallel. But the charging situation for these cells is not clear, particularly if they feature a power path circuit - it could apply 5V directly to the output when USB power is plugged in, which would blow out the ESP32.
Also, it appears from the ESP32 datasheet that there is an even lower power state than deep sleep, and that is hibernation mode, which leaves only the RTC function enabled. It says hibernation mode current is 5uA. I've seen nothing about how this works.
The answer to that is a solid "no". If you don't believe me, consider the implications of the register descriptions in the data sheet, and the fact that it requires processor intervention. Mull that over... decide for yourself.
aarg: ok I believe you.
So the only solution is to put FETs: one at the battery level and another one at the power input to be able to shutdown the Arduino with INT/SQW of the DS3231. Correct?