I want to include a RTC IC for accurate time measurment on a PCB that uses an ESP32S3 MCU. So this is not about a RTC modul that is connected by cables, but an IC that is soldered directly on a self made PCB.
For the project, power saving is very important. Since the SCL and SDA traces have to be pulled high by 10k ohms resistors, those would be powered all the time (even is the ESP32 is in deep sleep) if they were using the power the ESP32 uses.
Since I do not have the place left for a MOSFET and the energy consumption is really low, I thought about using an IO pin that is set high for the short time the RTC is used by the MCU (once an hour).
The ESP32 and the VCC of the RTC is powered directly raw from the LiFePo4 without an LDO (please no warnings about that practice).
My question is: would that idea work?
So it would be this power config:
LiFePo4 -> directly to RTC, ESP32 and pullup for interrupt
LiFePo4->Esp32->pullup for i2c for the datalines
All the Flags in the schematic are connected to GPIO pins, only B+ is connected directly to a LiFePo4 battery which voltage range is in the specification of the external RTC.
The pullups will only draw current if something pulls SCL or SDA low. Devices in deep sleep generally don't do that, so current consumption is virtually zero.
I think you're trying solve a nonexistent problem.
What @rsmls says can be verified(I believe it to be correct, but you may have doubts) by measuring the voltage on SCL/SDA when the unit is in deep sleep. If the voltage at both ends of the pullup resistor is the same, no current is flowing, and the problem is a ghost. If you have a voltage drop, you have a current, and are right to be concerned.
However, if you really want to minimize current, you should take note of the fact that the DS3231 has an oddball power setup. If you power it through its Vcc pin, it will draw about 100uA when it is only timekeeping and nothing else is going on. But if you power it through the Vbat pin, it only draws about 2uA. (Actually these values are for the DS3231SN, and may be slightly different for the M.) That's a significant difference for battery power.
So if you aren't using a backup coin cell, I'd suggest you power through Vbat. You can switch power to the pullups, or not, depending on the results of your testing of the current draw.
But note that Wire.h may leave pullups enabled on the processor side, so if you remove power from the external pullups, some current may flow through the processor pullups. That can be avoided by changing the pinMode() of the two I2C pins to INPUT immediately after Wire.begin().
For future reference, I have a circuit using the ZS-042 module, which does have a coin cell on which the DS3231 runs even when the main processor is running. I turn on the RTC module's Vcc pin via a GPIO only during I2C activity, and that pin powers the RTC through Vcc, and also powers the pullups. This seems to work fine, and doesn't require any delays.
For further information on the Vcc vs Vbat power draw, I highly recommend Edward Mallon's video on this subject, including how he makes it work when using the coin cell backup. It's part of the Cave Pearl Project, which is his underwater data logging thing, where battery life is crucial.
I dont know why I was thinking that the full potential of current flow of the 10k resistors would drainy my battery... you are totally right.
I switched them back to the be powered by the normal power line.
Unfurtunately since it is an SMD project and the components will arrive with the finished PCB, I wont be able to test the actual power lines on their own. I will try to measure without the RTC soldered yet
running a sketch on the almost finished ESP32 PCB before soldering the RTC
deep sleep consumption
then soldering the SMD RTC like in the new schematic
running a sketch that uses the RTC i2c actively
running one without using i2c
and then having the esp32 in deep sleep with the RTC soldered.
This is a very good point!
I've read the datasheet again and it even mentions that the Vcc pin does not have to be used at all. The power consumption is much lower, as you said, and the i2c functions normally with vbat. The difference seems to be the temperature measurment which is every 10 seconds instead of every second. Since the accuracy of a RTC is influenced by temperature changes that might have a little influence on it, but I think every 10 seconds is still enough and much better than the ICs that dont use temperature at all.
May I ask why you power it via Vcc when there is i2c activity? So the higher energy consumption is taken from the bigger battery that powers the MCU instead of the small vbat one? Because according to the datasheet, the i2c should function even if the Vcc is floating or soldered to ground and it is only powered by vbat. Since both vcc and vbat can be supplied by 2.3v to 5.5v, the small battery cell seems not really necessary and it can be powered raw by the bigger LiPo or LiFePo4 that also powers the MCU without regulation at all, and the power consumption would be lower when powering it through vbat all the time.
I changed the schematic accordingly and will still use the idea of powering via a GPIO pin for a temperature and humidity sensor that I have just included, since that one doesnt need to be powered all the time
Edit:
I have one more question about the technical background of powering from a GPIO pin.
In the datasheet of the temperature sensor, it is said
The pull-up voltage of SCL and SDA must be powered by VDD, and the power supply voltage range is 2.2-5.5V
Does it make a difference if the VDD and SDA/SCL are not powered by by the same net/powerline and thus have a slightly different voltage? Since I dont fully understand this remark in the datasheet.
In projects like these, I generally also get some of the pin-header equipped amateur modules to experiment and prototype with. I must have one of these RTC modules somewhere, for instance!
Not as long as you don't violate any of the ratings of the IC. In particular, these ratings tend to include things like "don't take SCL/SDA higher than Vcc + 0.5V" etc. The "0.5V" is a guess; you'll find the applicable number in the datasheet. Generally a difference of e.g. 0.3V is not a problem.
Yes, I just found it in the datasheet, it mentions +-0.3V aswell, which is not much.
So to be safe, I might just power the interrupt pullup with the steady power line and the i2c from an IO pin. Not for power saving, but for reliability.
So: the RTC Vbat and interrupt pullup have a steady power
and the i2c and temperature sensor are powered by an GPIO only when outside of deep sleep and a measurment is taken.
It's due to the module I was using - the ZS-042. To get power to the I2C pullups, you have to provide power to the module's Vcc header. But that also provides power to the DS3231's Vcc pin. If I weren't so lazy, I would have lifted pin 2, or cut the trace going to it, but then I would also need to ground it I think. So I just left the module alone, and figured for the very brief periods Vcc would be used, it wouldn't make much difference.
But since you're laying out your board, you would just power the RTC through Vbat all the time, and independently power the pullups. And even if you were using a backup coin cell, you could still power it all the time from that, and it would probably last a couple years.
I know in theory there shouldn't be any current flow through the pullups when I2C is idle, but I have a dim recollection of a case where that wasn't true. Somethiing involving a Ralph Bacon video. In any case, I think you do want to test this after Wire.begin(). If there really is no current, then you can just power the pullups all the time, and save the GPIO pin.
Edit: I forgot to bring up the fact that you have at least one other I2C device in your circuit. This may complicate how you handle powering the I2C pullups. if you power down the other device, its I2c pins may draw current by way of its protection diodes. So if your ESP32 has multiple I2C peripherals, you may want to use separate busses for the I2C devices.