ATMega328p sleep mode with RTC3231 power consumption

Hi, I need a urgent help on this, I need to build a system with atmega328p and ds3231, the system will do some operation for every 1hr, I am using standalone atmega328p chip, it will be in power down mode when rtc interrupts it starts and does the operation and it will go to sleep, this function works fine now, but my problem is the power consumption because the atmega328p draws 7mA on active and 0.22uA on power down mode which is ok for me, but the RTC consumes around 1.8mA all the time, which is not acceptable for a battery budget system, even I have removed the power led from rtc ds3231 but no luck. Somewhere I have heard that ds3231 consume only 100uA but it's not for me, so please advice on this for me to go ahead. Thanks in advance.

When powered down and running off the battery input the DS3231 only draws about 1uA. That should be your goal. Are you using a breakout board that makes this difficult?

Maybe you are also drawing too much current with the 328p. At 3.3V and 8MHz it should be about 3mA. Do you need a higher voltage and/or clock frequency?

I am using the standalone arduino atmega328p chip on breadboard, when the arduino is power down it draws only 22uA but RTC connected to vcc draws about 2mA.

Then power down the RTC before going to sleep so its running from Vbat only.

Oh, but how to power down the RTC, if I power down, will interrupt work ?

Connect a digital pin to Vcc on the DS3231. The interrupt does work when the RTC is powered down. I tested it myself. A long thread: http://forum.arduino.cc/index.php?topic=346940.0

OK thanks bro, I will try it by tomorrow and let you know.

Hi I have connected as you said, connected digital pin to vcc of RTC ds3231 and when the atmega328p is in power down mode the alarm is not triggered. Any advice ?

superbaj1986:
Hi I have connected as you said, connected digital pin to vcc of RTC ds3231 and when the atmega328p is in power down mode the alarm is not triggered. Any advice ?

It worked for me.

I suspect something is wrong with your code, the way you've hooked it up or both. If you want someone to help you figure it out you'll have to start supplying details.

Hi, JBoyton, please have a look on my below code, the power to RTC from D9 pin of arduino and its set to LOW before atmega328p goes to powerdown, now the alarm interrupt is not working, but when i dont set the D9 pin to LOW it works perfect but it draws around 1.3mA(0.28uA for atmega328p and 1mA for RTC) please have look and you will get an idea, if more details needed please let me know.

Note:- I am using the bareboard atmega328p with 16mhz clock. i am using the bareboard for this low power project.

---------Connection Details------------------------------------------------------------------

RTC Vcc → D9
RTC Gnd → Gnd
RTC SDA → A4
RTC SCL → A5
RTC SQW → INT0(PIN 2)

---------Sketch-----------------------------------------------------------------------------

#include <DS3232RTC.h> //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h> //http://arduiniana.org/libraries/streaming/
#include <Time.h> //http://playground.arduino.cc/Code/Time
#include <Wire.h> //http://arduino.cc/en/Reference/Wire
#include <LowPower.h>
#include <VarSpeedServo.h>

#define SQW_PIN 2

VarSpeedServo myservo;
volatile boolean alarmIsrWasCalled = false;
int led_pin = 13;
int rtc_power_pin = 9;

void setup(void)
{

pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, LOW);
pinMode(rtc_power_pin, OUTPUT);
digitalWrite(rtc_power_pin, HIGH);

Serial.begin(115200);

setSyncProvider(RTC.get);
Serial << “RTC Sync”;
if (timeStatus() != timeSet)
{
Serial << " FAIL!";
}
Serial << endl;

RTC.squareWave(SQWAVE_NONE);
pinMode(SQW_PIN, INPUT_PULLUP);
attachInterrupt(INT0, alarmIsr, FALLING);

//Set an alarm at every 20th second of every minute.
RTC.setAlarm(ALM1_MATCH_SECONDS, 20, 00, 0, 1);
RTC.alarm(ALARM_1);
RTC.alarmInterrupt(ALARM_1, true);

//Set an alarm every minute.
RTC.setAlarm(ALM2_MATCH_MINUTES, 00, 59, 0, 1);
RTC.alarm(ALARM_2);
RTC.alarmInterrupt(ALARM_2, true);
}

void alarmIsr()
{
alarmIsrWasCalled = true;
}

void loop(void)
{

if (alarmIsrWasCalled){
if (RTC.alarm(ALARM_1)) {
digitalWrite(led_pin, HIGH);
delay(5000);
digitalWrite(led_pin, LOW);

}
if (RTC.alarm(ALARM_2)) {
//need to write some logic

}

alarmIsrWasCalled = false;
digitalWrite(rtc_power_pin, LOW); //if this line is commented it works as expected.
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}
}

Edit your post and put your code in code tags.

Sorry, I don't see an obvious error.

I got out the breadboard with my RTC on it and connected it to a bare Atmega328p. The alarm woke up the processor periodically as expected. In between alarms the current was 0.9uA. I didn't measure the current to the backup battery but it was probably something similar.

I didn't use your code for a couple of reasons. First, I didn't want to download all of those libraries. Secondly I have the SPI version of the chip, the DS3234. It's otherwise functionally equivalent. And people with DS3231 chips have confirmed that the alarm works when the RTC is powered down.

Maybe it has something to do with how your circuit is physically wired. What is the voltage on the interrupt pin when the DS3231 is powered down?

edit: I do see an error. You never turn the power back on to the RTC. When you get an interrupt you have to write to a register to reset the interrupt flag or else you'll never get another interrupt. The rtc.alarm() function reads the flag and then, if it's set, resets it. You have to power up the DS3231 to read/write those registers.

Hi thanks for your input JBoyton, can you please provide me the corrected code ? , because i am not an expert or electronic student, even i dont understand what is registers you are speaking too i am from the IT background, i am doing this for one of my personal project. so can you guide me on the code level if possible ? please help on this.

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h>        //http://arduiniana.org/libraries/streaming/
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire
#include <LowPower.h>
#include <VarSpeedServo.h>

#define SQW_PIN 2

VarSpeedServo myservo;
volatile boolean alarmIsrWasCalled = false;
int led_pin = 13;
int rtc_power_pin = 9;


void setup(void)
{

    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, LOW);
    pinMode(rtc_power_pin, OUTPUT);
    digitalWrite(rtc_power_pin, HIGH);
   
    Serial.begin(115200);
   
    setSyncProvider(RTC.get);
    Serial << "RTC Sync";
    if (timeStatus() != timeSet)
    {
      Serial << " FAIL!";
    }
    Serial << endl;

   
    RTC.squareWave(SQWAVE_NONE);
    pinMode(SQW_PIN, INPUT_PULLUP);
    attachInterrupt(INT0, alarmIsr, FALLING);


    //Set an alarm at every 20th second of every minute.
    RTC.setAlarm(ALM1_MATCH_SECONDS, 20, 00, 0, 1);
    RTC.alarm(ALARM_1);
    RTC.alarmInterrupt(ALARM_1, true);

    //Set an alarm every minute.
    RTC.setAlarm(ALM2_MATCH_MINUTES, 00, 59, 0, 1);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_2, true);
}


void alarmIsr()
{
    alarmIsrWasCalled = true;
}

void loop(void)
{
 
 
    if (alarmIsrWasCalled){
        if (RTC.alarm(ALARM_1)) {
             digitalWrite(led_pin, HIGH);
             delay(5000);
             digitalWrite(led_pin, LOW);
                 
        }
        if (RTC.alarm(ALARM_2)) {
           //need to write some logic
                     
        }
       
        alarmIsrWasCalled = false;
        digitalWrite(rtc_power_pin, LOW); //if this line is commented it works as expected.
        LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
    }
}

My suggestion would be to do what I have done in some of my power-reduction sketches, and just use the watchdog timer to sleep, and periodically check the clock, and if time is up, do whatever you need to do.

Hi Gammon,
I need it through the RTC because i need to run arduino on the time specified even if the arduino restarts, so anyone please help on RTC.

Just turn the RTC power back on when you wake up.

My temperature and humidity sensor uses low power, and has a RTC. You should be able to get some clues from that.

Hi jboyton,
I agree with you, but to power on the RTC I need to get the wake up interrupt from the RTC right, which is I am not getting right now, when I power off the RTC via digital pin the alaram interrupt is not working, so can you help on this, key me know if more details needed.

superbaj1986:
...when I power off the RTC via digital pin the alaram interrupt is not working

How do you know it isn't working?

Hi Jboyton,
Can you please correct my sketch if possible, I don't know where I have to put, please help on this.

Sometimes I wish I were Grumpy Mike.