I'm trying to create a highly accurate, self-setting clock based on an Adafruit Huzzah32 (esp32), a GPS (with a PPS) and a DS3231 RTC. I got the GPS working, I'm able to parse the NMEA sentences and see the interrupts every second. However, I'm not able to get the DS3231 interrupts working properly. I am able to set and read the time from the DS3231 but the per-second interrupts don't seem to trigger. I've verified the interrupts are never triggering on my oscilloscope.
I have directly connected the SQW/INT breakout on the DS3231 Feather Wing to A2/GPI #34 breakout spot on the Feather Wing. I choose that "pin" because it was the closest to the SQW/INT spot on the Feather Wing. I have the following code, but the "rtcHandler()" function never gets called:
#include <RTClib.h>
RTC_DS3231 rtc;
const byte RTC_pin = 34;
bool rtcHandlerCalled = false;
void rtcHandler() {
rtcHandlerCalled = true;
Serial.println("rtcHandler()!");
}
void setAlarm() {
rtc.disable32K();
pinMode(RTC_pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RTC_pin), rtcHandler, FALLING);
rtc.clearAlarm(1);
rtc.clearAlarm(2);
rtc.writeSqwPinMode(DS3231_OFF);
rtc.disableAlarm(2);
if (!rtc.setAlarm1(rtc.now(), DS3231_A1_PerSecond)) {
Serial.println("Couldn't set alarm");
} else {
Serial.println("Alarm set");
}
}
void setup() {
Serial.begin(115200);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(2020, 12, 29, 3, 0, 0));
}
setAlarm();
}
void loop() {
if (rtcHandlerCalled) {
rtcHandlerCalled = false;
Serial.println("RTC Handler called");
}
}
I see "Alarm set" on the serial console, but nothing after that. What am I missing?
