Hi All,
I've been working on adding a DS3231 RTC to a project that's running Arduino on an ESP8266 (I will add Wifi later). I've had success with the DS1307 but I wanted to make use of the alarm functions that the DS3231 provide.
I've been able to set and read the time using Adafruit's RTClib but I've moved on to "DS3232RTC" library provided by: GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks since a lot of folks seem to use that one for setting and handling the alarms (the Adafruit library doesn't mention any alarm functions).
My Hardware:
ESP8266 running Arduino 1.6.12
DS3231 SDA > pin 4 on ESP
DS3231 SCL > pin 5 on ESP
DS3231 SQW > 10K pullup resistor to VCC & pin 14 on ESP
My Issue: the sketch below complies and uploads but immediately throws the following errors in the Monitor:
"ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset
ets Jan 8 2013,rst cause:4, boot mode:(1,7)
wdt reset"
Then nothing. I can always go back and load different sketches and they all compile and run successfully so I don't think there's a wiring issue. I've also deleted and redownloaded the DS3232RTC library to make sure my copy wasn't corrupted. I've been googling those error messages and a lot of the solutions I'm finding relate to wiring and insufficient power issues. But if I'm able to load different sketches with the same wiring/powering setup, that shouldn't be an issue, correct? I'm out of ideas.
Has anyone run into this issue before? Is it related to my other libraries? It must be related to my sketch but I can't figure out where exactly. Any help is greatly appreciated!!
#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include <DS3232RTC.h>
volatile boolean alarmFlag = false;
void setup() {
Serial.begin(115200);
delay (1000);
Serial.println("initializing DS3231");
setSyncProvider(RTC.get);
RTC.squareWave(SQWAVE_NONE);
RTC.alarmInterrupt(ALARM_1, false);
RTC.alarmInterrupt(ALARM_2, false);
RTC.setAlarm(ALM1_MATCH_SECONDS, 20, 0, 0, 2);
RTC.alarmInterrupt(ALARM_1, true);
pinMode(14, INPUT);
attachInterrupt(14, alarmISR, FALLING);
}
void loop() {
time_t currentTime;
currentTime = RTC.get();
Serial.println(currentTime);
if (alarmFlag == true) {
Serial.println("the 20 second alarm just went off!");
alarmFlag = false;
}
delay (1000);
}
void alarmISR() {
alarmFlag = true;
}