How to stop current draw through Analog Input

Hello all,

I (almost) finished my data logger but I have a final question. The logger is using an DS3231 RTC to get date/time for each measurement taken. The logger is most of the time in Power-Down-Mode and it is important that the current flowing is limited as much as possible. Right now the Logger is taking about 0.47mA in pwr-dwn-mode which is more than without the RTC. The RTC is drawing 0.2mA through both analog signal wires.

My question: How can I stop the current draw through the analog input connections (SCL, SDA) of the RTC module? (I'm using the DS1307 library).

Thanks.

How is the 5V of the RTC used ? When that is turned off and the I2C is off, and also the power to the pullup resistors for the I2C bus is off, then there is no current flowing through the pullup resistors.

In power down, only the battery has a voltage, which is supplied to a single pin on the RTC.

Thanks for answering,

I switch the 5V for the RTC module through a digital AVR pin on and off. Both signal wires (SDA and SCL) goes straight to the analog input pins 4 and 5 (it’s a 328P chip). How can I switch off the I2C? How can I use pull-ups with analog inputs?

Thanks.

I think that RTC module has onboard pullup resistors for I2C. Can you confirm that ? Is a schematic available ?

The Wire library turns on the internal pullup resistors of the ATmega328P for the I2C bus. They are 50k or 70k or so. The current is 5V / 50k = 0.1mA, and for both SDA and SCL it is 0.2mA.

I'm not sure, but I think you can turn those off like this:

void setup()
{
  Wire.begin();              // turns on internal pullup.
  digitalWrite( SDA, LOW);  // turns off internal pullup.
  digitalWrite( SCL, LOW);  // turns off internal pullup.
  ...

Unfortunately I do not have a schematic of the module. I tried to set the analog inputs low before going to sleep and indeed the 0.2mA is not drawn anymore. But it will stop working in the second loop when the RTC module is powered up. ???

I don't know if the Wire library gets confused when both SDA and SLC are low and nothing is happening at that moment.

When you turn on the power pin for the VCC of the RTC module, do you wait some time ? Try waiting 500ms. Perhaps there is a capacitor on the board that needs to charge before the pullup resistors start working.

It mysteriously works now. I followed your suggestion to have a bigger delay between powering the RTC module and reading the time:

analogWrite(RTCPower, 255);       // switch RTC on
delay(500);

  if (! RTC.isrunning()) {
      analogWrite(errorLED, 0);
      return;
  }
  
  //Serial.println(F("I'm awake..."));
  //delay(100);
  
  DateTime now = RTC.now();
...

pinMode(A4, INPUT);          // turns off analog 4
pinMode(A5, INPUT);          // turns off analog 5
pwrDown(10);                   // go to sleep for 10 seconds

Thanks for your help.

You can try to lower the value to see how much delay is needed. If for example 100ms is the limit, choose at least twice that (200ms) in the sketch.

Could you use the power pin in a digital way ? In setup() : pinMode ( RTCPower, OUTPUT ) ; turn it on : digitalWrite ( RTCPower, HIGH ) ; turn if off : digitalWrite ( RTCPower, LOW ) ;

The schematic for that ebay DS3231 module can be found on this excellent blog page

It does have pullups on SDA and SCL, which are in a small chip that can easily be removed using a soldering iron. There are a number of other problems with it. If you use a CR2032 cell, the cell will quickly be destroyed by the charging circuitry, so you will at least want to remove the 200 ohm resistor. You may also want to remove the 1K resistor for the idiotic LED.

It is an interesting question whether the DS3231 chips (about US$ 8 at Digikey) on them are counterfeit. I have a couple of the same modules and in my tests they are seriously out of spec. So far I've determined that one of them loses 1-2 seconds per day, which is not bad but nowhere near the accuracy of a genuine DS3231 chip. The other is still in testing.

BTW did your module come with a rechargeable LiR cell, or a nonrechargeable CR2032?

I have a data logger including RTC, which uses very little current (around 7 µA when idle):

http://www.gammon.com.au/forum/?id=12106

@jremington: Thanks for the very interesting link. I was a little bit surprised about the cheap price and was wondering how they can do it.

Anyway, the whole module is running just for few seconds once an hour and completely switched off from the board, thus from the power supply. With setting both I2C pins on the AVR as input before going to sleep no current is drawn anymore and the chip is sleeping at 25 µA. Which is totally fine for me. Thanks for the link and I'll have a look to the battery...

EDIT: I had a look on the battery and indeed its a LiR cell... I might follow your suggestion to get rid of the charger section on the RTC board. I need the RTC running more than just 200 days (best case). Thanks for pointing me ...

jremington, can you write a page about possible counterfeits DS3231 ? and post about it in this topic ? I remember now that I have that same module and I removed the diode (easier to spot the right component) and use a normal battery. It was very cheap on Ebay, but luckely mine is accurate.

Peter_n: jremington, can you write a page about possible counterfeits DS3231 ? and post about it in this topic ?

Did he not already do that by citing the link?

Have you read it?

Thanks Paul_B, I only scrolled down on that page to see the schematic :-[ I'm reading it now :P Is the conclusion : They are too cheap to be true, but still within the specifications of the manufacturer ?

Peter_n: Is the conclusion : They are too cheap to be true, but still within the specifications of the manufacturer ?

Ah, dear me, it is a complex matter.

I get really pi$$ed off at how many of my domestic appliances become faulty with intermittent failure. Of course, that is not necessarily to do with microchips, though sometimes it is. ADSL modems and VoIP boxes failing - I really just want to install them and have them work for a reasonable lifetime - ten years or so is not too much to expect. Presently I am faced with repairing my PABX which is just short of 30 years old and has required repair before. Frankly I see no reason not to expect it to work for another 20 years; sure there are more modern systems out there now but why should I have to replace it? All I want to do is to dial up people and talk to them. (Voicemail is grossly offensive most of the time.)

Clearly a lot of the stuff we buy is third-grade. Even "big name" products are suspect sometimes. Quality electronics should last 50 years and like the PABX, much of the time the requirement does not change in that interval. Who actually needs an Internet toaster?

But we are not getting quality. Clearly, counterfeiting is all too real, but it covers a wide variety of practices, from outright rubbish to products which may well work better than the original. We just have to live with it, it seems. Far too many people on this earth to do otherwise. :astonished:

No, as I stated, my ebay DS3231 modules are out of spec (but still much better than DS1307s).

I bought a couple of the JeeLabs RTCs, which use the genuine DS3231 chips. They are spot on after 6 months. http://jeelabs.net/projects/hardware/wiki/Precision_RTC_Plug

Thanks. It is still confusing for me, and waiting for 6 month to test if it is genuine is a long time :sleeping:

I had to wait just 10 days to figure out that my ebay DS3231s were both seriously out of spec. However, there is a "aging" register that allows small adjustments to the oscillator compensation circuit and I'm hoping that will take care of the drift. If you want to log data for up to a year at a time (as I do), you probably need that accuracy! The DS1307 is hopeless for such applications.

By comparing the rising edge of the RTC 1Hz square wave output to that of the 1 Hz PPS output of a GPS unit with a good satellite lock, you can determine within a few hours how much the RTC is drifting. I'm setting that up now.

See http://www.romanblack.com/onesec/High_Acc_Timing.htm (no need to use a PIC, though).

Any idea yet what is wrong with them ? Are they really counterfeits or a rejected batch.

Suppose a factory can make a DS1307 clone, and adds a crystal and a temperature sensor (a diode), and adjusts the crystal according to the temperature sensor, either analog or digital with a microcontroller. That would increase the accuracy a lot, and perhaps it is possible to make that for less than a dollar.

I would guess that the chips are from a rejected batch, because everything else seems to work correctly. For example, there is a temperature sensor in the DS3231 and that is functioning within spec. The author of the blog article I linked above commented that all of his examples were slow too.