This is a real PITA.
I canno after trying pretty much every permutation of code how to get a valid seconds timeout
using this library.
The following code works, unless I change INTER_MAX to anything above 1 and logically
I think it should work.
Any ideas guys before the big Arduino hammer comes out of the toolbox?
// Test DS3231 RTC interrupts
#include <Arduino.h>
#include <Wire.h>
#include "DS3231.h"
#define INT0_PIN 2 // Interrupt 0 is on Digital Pin 2
#define INT0_NUM 0 // Interrupt 0 is 0
#define INT0_TRIG FALLING // LOW, CHANGE, RISING, *FALLING
#define INTER_MAX 1
#define RTC_POW_POS A2 // to power RTC
#define RTC_POW_GND A3 // to power RTC
#define RGB_RED_LED 9 // Red in RGB LED
#define RGB_GRN_LED 10 // Green in RGB LED
#define RGB_BLU_LED 11 // Blue in RGB LED
DS3231 RTC; // Create a DS3231 object
volatile int inter_count;
//-------------------------------------------------------------------------------------------
void setup(void)
{
pinMode(RGB_RED_LED, OUTPUT);
digitalWrite(RGB_RED_LED, LOW);
pinMode(RGB_GRN_LED, OUTPUT);
digitalWrite(RGB_GRN_LED, LOW);
pinMode(RGB_BLU_LED, OUTPUT);
digitalWrite(RGB_BLU_LED, LOW);
delay(100);
pinMode(RTC_POW_POS, OUTPUT); // +5v supply for RTC
digitalWrite(RTC_POW_POS, LOW); // +5v supply for RTC
pinMode(RTC_POW_GND, OUTPUT); // GND supply for RTC
digitalWrite(RTC_POW_GND, HIGH); // GND supply for RTC
//cli(); // turn off interrupts until settings are done
// INT0 to accept interrupts
PORTD |= 0x04;
DDRD &=~ 0x04;
pinMode(INT0_PIN, INPUT_PULLUP);
Serial.begin(115200);
Wire.begin();
RTC.begin();
Serial.println("Started");
RTC.enableInterrupts(EverySecond); //interrupt at EverySecond, EveryMinute, EveryHour
inter_count = 0;
attachInterrupt(INT0_NUM, int0_wake, INT0_TRIG);
//sei(); // turn interrupts back on
}
//-------------------------------------------------------------------------------------------
void loop ()
{
if (inter_count >= INTER_MAX)
{
RTC.clearINTStatus();
//noInterrupts ();
//detachInterrupt(INT0_NUM);
digitalWrite(RGB_GRN_LED, LOW);
digitalWrite(RGB_RED_LED, HIGH);
delay(10);
digitalWrite(RGB_RED_LED, LOW);
// reset interrupt count
inter_count = 0;
//RTC.enableInterrupts(EverySecond); //interrupt at EverySecond, EveryMinute, EveryHour
//attachInterrupt(INT0_NUM, int0_wake, INT0_TRIG);
//interrupts();
}
}
//-------------------------------------------------------------------------------------------
void int0_wake()
{
inter_count++;
digitalWrite(RGB_GRN_LED, HIGH);
}
//-------------------------------------------------------------------------------------------