DS3231 in Power Saving and trigger interrupt

i'm using Ds3231 RTC to wake up my arduino from sleep mode.
What i want to do is to power up the RTC via arduinos digital pin in order to save some power while the system is in sleep mode.
Following what is suggested here Gammon Forum is not working for me(i can't wake up the arduino from sleep ).

Any idea why ?
What i want to do is....doable ?

Thank you.

Any idea why ?
There is a problem with your program.

What i want to do is…doable ?
Yes.

Thank you jremington for your reply…

here is my … problematic code :blush: :smiley:

#include <DS3231.h>
#include <Wire.h>
#include <avr/sleep.h>

DS3231 Clock;
byte year, month, date, DoW, hour, minute, second;

int INTERRUPT_PIN = 2;
int RTC_ON = 9;       // D5 DHT PIN (ON - OFF)
volatile int flag = 0;

void setup () {
  
  digitalWrite (RTC_ON, HIGH);
  pinMode (RTC_ON, OUTPUT);
  pinMode(INTERRUPT_PIN, INPUT);
  //pull up the interrupt pin
 // digitalWrite(INTERRUPT_PIN, HIGH);
  
  Serial.begin(19200);
  Wire.begin();
  
  Clock.getTime(year, month, date, DoW, hour, minute, second);
  Clock.setA1Time(DoW, hour, minute+1, second, 0x0, true, false, false);
  // set A2 to two minutes past, on current day of month.
  Clock.setA2Time(date, hour, minute+2, 0x0, false, false,false);
  // Turn on both alarms, with external interrupt
  Clock.turnOnAlarm(1);
  Clock.turnOnAlarm(2);

  if (Clock.checkAlarmEnabled(1) && Clock.checkAlarmEnabled(2)) {
    Serial.println("Alarms Enabled");
  }
  attachInterrupt(0, SendReport, FALLING);
}


void loop () {
  
  // power up clock chip
  digitalWrite (RTC_ON, HIGH);
  pinMode (RTC_ON, OUTPUT);

  // activate I2C
  Wire.begin();

  
  //DateTime now = RTC.now();
  if (Clock.checkIfAlarm(1) ) 
  {
    Serial.println("Alarm 1 Triggered");
  }
  if (Clock.checkIfAlarm(2)) 
  {
    Serial.println("Alarm 2 Triggered");
  }
  if(flag ==1)
  {
    Serial.println("FLAG = 1");
    delay(2000);
  }
  else
  {
    Serial.println("FLAG = 0");
    delay(2000);
  }
  // Display the time once more as a test of the getTime() function
 Clock.getTime(year, month, date, DoW, hour, minute, second);
 
        Serial.print(year, DEC);
        Serial.print("/");
 Serial.print(month, DEC);
        Serial.print("/");
 Serial.print(date, DEC);
        Serial.print("day of the week :");
 Serial.println(DoW, DEC);
 Serial.print(hour, DEC);
        Serial.print(":");
 Serial.print(minute, DEC);
        Serial.print(":");
 Serial.println(second, DEC);

// finished with clock
  pinMode (RTC_ON ,INPUT);  
  digitalWrite (RTC_ON, LOW); 

  // turn off I2C
  TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));

  // turn off I2C pull-ups
  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);

        Serial.println("Going to Sleep");
        delay(600);
  sleepNow();
  Serial.println("AWAKE");
}

void sleepNow() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(0,SendReport, FALLING);
  sleep_mode();
  //HERE AFTER WAKING UP
  sleep_disable();
  detachInterrupt(0);
}

void SendReport() {
  
  //do something quick, flip a flag, and handle in loop();
   flag =1 ;
}

The above working when DS3231 powered from VCC and NOT when powered from RTC_ON pin.

What does the hardware look like?

This thread might be helpful:

DS3231 - No Alarm when powered Off. Why?

Yep jboyton …i found the thread AND the solution !
Hardware modification needed in order to work.
See in … DS3231 - No Alarm when powered Off. Why? on how to make this mod.

Below is my test code in case that is useful to someone.

#include <DS3231.h>
#include <Wire.h>
#include <avr/sleep.h>

DS3231 Clock;
byte year, month, date, DoW, hour, minute, second;

int INTERRUPT_PIN = 2;
int RTC_ON = 9;       // D5 DHT PIN (ON - OFF)
//digitalWrite (RTC_ON, HIGH);
volatile int flag = 0;

void setup () {
  
  digitalWrite (RTC_ON, HIGH);
  pinMode (RTC_ON, OUTPUT);
  pinMode(INTERRUPT_PIN, INPUT);
  //pull up the interrupt pin
  digitalWrite(INTERRUPT_PIN, HIGH);
  
  Serial.begin(19200);
  Wire.begin();
  
  Clock.getTime(year, month, date, DoW, hour, minute, second);
  Clock.setA1Time(DoW, hour, minute+1, second, 0x0, true, false, false);
  // set A2 to two minutes past, on current day of month.
  Clock.setA2Time(date, hour, minute+2, 0x0, false, false,false);
  // Turn on both alarms, with external interrupt
  Clock.turnOnAlarm(1);
  Clock.turnOnAlarm(2);

  if (Clock.checkAlarmEnabled(1) && Clock.checkAlarmEnabled(2)) {
    Serial.println("Alarms Enabled");
  }
  attachInterrupt(0, SendReport, LOW);
}


void loop () {
  
  // power up clock chip
  digitalWrite (RTC_ON, HIGH);
  pinMode (RTC_ON, OUTPUT);

  // activate I2C
  Wire.begin();

  
  //DateTime now = RTC.now();
  if (Clock.checkIfAlarm(1) ) 
  {
    Serial.println("Alarm 1 Triggered");
  }
  if (Clock.checkIfAlarm(2)) 
  {
    Serial.println("Alarm 2 Triggered");
  }
  if(flag ==1)
  {
    Serial.println("FLAG = 1");
    delay(2000);
  }
  else
  {
    Serial.println("FLAG = 0");
    delay(2000);
  }
  // Display the time once more as a test of the getTime() function
	Clock.getTime(year, month, date, DoW, hour, minute, second);
	
        Serial.print(year, DEC);
        Serial.print("/");
	Serial.print(month, DEC);
        Serial.print("/");
	Serial.print(date, DEC);
        Serial.print("day of the week :");
	Serial.println(DoW, DEC);
	Serial.print(hour, DEC);
        Serial.print(":");
	Serial.print(minute, DEC);
        Serial.print(":");
	Serial.println(second, DEC);

// finished with clock Turn it Off
  pinMode (RTC_ON ,INPUT);  
  digitalWrite (RTC_ON, LOW); 

  // turn off I2C
  TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));

  // turn off I2C pull-ups
  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);

        Serial.println("Going to Sleep");
        delay(600);
  sleepNow();
  Serial.println("AWAKE");
}

void sleepNow() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  attachInterrupt(0,SendReport, LOW);
  sleep_mode();
  //HERE AFTER WAKING UP
  sleep_disable();
  detachInterrupt(0);
}

void SendReport() {
  
  //do something quick, flip a flag, and handle in loop();
   flag =1 ;
}