Hello: I’m unable to get the alarm working on the RTC 1805. I can set time, print time, print alarm but can’t get Example 4. Don’t have a scope but it looks like the INT pin goes low very briefly on my VOM. Also set 24 hour as I thought that might be the problem, but since I can print out the alarm int he registers, I know I have the correct time in there. Suggestions?
Can you host images of your setup and module in places like Google Drive or Imgur and share the links?
Brandon:
Not a lot to see on this setup, but here’s a pic:
I didn’t hook up the interrupt pin from the clock to the ThingPlus, just uncommented the code in the example sketch.
Here’s my version of the Example 4 sketch. Fixed the incorrect default SCL and SDA pins (arrggghh!) and added some diagnostic Serial.println statements:
/*
Getting the alarm to fire an interrupt on the RV-1805 Real Time Clock
By: Andy England
SparkFun Electronics
Date: 2/22/2017
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Feel like supporting our work? Buy a board from SparkFun!
https://www.sparkfun.com/products/14642
This example shows how to set an alarm and make the RTC generate an interrupt when the clock time matches the alarm time
The INT pin will be 3.3V. When the real time matches the alarm time the INT pin will go low.
Hardware Connections:
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
Plug the RTC into the shield (any port)
Open the serial monitor at 115200 baud
*/
#include <SparkFun_RV1805.h>
RV1805 rtc;
byte secondsAlarm = 1;
byte minuteAlarm = 37;
byte hourAlarm = 18;
byte dateAlarm = 27;
byte monthAlarm = 7;
bool alarmed = false;
void setup() {
Serial.begin(115200);
Serial.println("Alarm from RTC Example");
//added since default wrong for ThingPlus and Huzzah32
const int SCLpin = 22;
const int SDApin = 23;
byte deviceID;
Serial.println("\n*************\nSDA = "+String(SDA));
Serial.println("SCL = "+String(SCL));
Serial.println("SDA Pin = "+String(SDApin));
Serial.println("SCL Pin = "+String(SCLpin));
Wire.begin(SDApin, SCLpin);
//end of fw add
if (rtc.begin() == false) {
Serial.println("Something went wrong, check wiring");
}
//FW added 24 hour
rtc.set24Hour();
rtc.setAlarm(secondsAlarm, minuteAlarm, hourAlarm, dateAlarm, monthAlarm); //Sets the alarm with the values initialized above
/********************************
Mode must be between 0 and 7 to tell when the alarm should be triggered.
Alarm is triggered when listed characteristics match
0: Disabled
1: seconds, minutes, hours, date and month match (once per year)
2: seconds, minutes, hours and date match (once per month)
3: seconds, minutes, hours and weekday match (once per week)
4: seconds, minutes and hours match (once per day)
5: seconds and minutes match (once per hour)
6: seconds match (once per minute)
7: once per second
********************************/
//rtc.setAlarmMode(7); //Once per second
//rtc.setAlarmMode(6); //Once per minute
//rtc.setAlarmMode(5); //Once per hour: Alarm will go off every time there is a hundredths+seconds+minutes match (each hour)
rtc.setAlarmMode(5); //Alarm goes off every day
rtc.enableInterrupt(INTERRUPT_AIE); //Enable the Alarm Interrupt
}
void loop() {
if (rtc.updateTime() == false) //Updates the time variables from RTC
{
Serial.print("RTC failed to update");
}
String currentDate = rtc.stringDateUSA(); //Get the current date in mm/dd/yyyy format (we're weird)
//String currentDate = rtc.stringDate()); //Get the current date in dd/mm/yyyy format
String currentTime = rtc.stringTime(); //Get the time
Serial.print(currentDate);
Serial.print(" ");
Serial.println(currentTime);
//fw added
// Print alarm date and time (Note that there is no year alarm register)
char alarmBuffer[20];
Serial.print("Alarm: ");
sprintf(alarmBuffer, "2020-%02d-%02d %02d:%02d:%02d",
rtc.getAlarmMonth(),
rtc.getAlarmDate(),
rtc.getAlarmHours(),
rtc.getAlarmMinutes(),
rtc.getAlarmSeconds());
Serial.println(alarmBuffer);
sprintf(alarmBuffer, "%04d", rtc.getYear());
Serial.println(alarmBuffer);
Serial.println();
byte rtcStatus = rtc.status(); //Get the latest status from RTC. Reading the status clears the flags
if(rtcStatus != 0)
{
Serial.println("An interrupt as occured: ");
//Determine which bits are set
if(rtcStatus & (1<<STATUS_CB)) Serial.println("It's a new century!");
if(rtcStatus & (1<<STATUS_BAT)) Serial.println("System is on backup battery");
if(rtcStatus & (1<<STATUS_WDF)) Serial.println("Watchdog timer trigger");
if(rtcStatus & (1<<STATUS_BLF)) Serial.println("Battery is below threshold");
if(rtcStatus & (1<<STATUS_TF)) Serial.println("Countdown timer at zero");
if(rtcStatus & (1<<STATUS_AF))
{ Serial.println("Alarm went off!");
alarmed = true;
}
if(rtcStatus & (1<<STATUS_EVF)) Serial.println("External event detected");
delay(2000);
}
delay(1000);
if (alarmed) {
Serial.println("Alarm fired!");
}
}
OK. Here’s an odd one. Newbie added the following diagnostic code to see what the Interrupt Mask at 0x12 is. If these lines are in my sketch, the alarm fires per the uncommented Serial.Print parts at the bottom of the sketch. IF I COMMENT OUT THE READING OF THAT REGISTER, the alarm doesn’t fire.
Well at least I’ve got it firing
oops and here’s the code I added:
Serial.print(" InterruptMASK: ");
byte rtcStatus = rtc.status(); //Get the latest status from RTC. Reading the status clears the flags
const byte MASK = 0x12;
byte rtcIntMask = rtc.readRegister(MASK);
Serial.println(rtcIntMask, BIN);
I know this is an old post but I’m having the same problem with the rv1805. The alarm just won’t trigger… Did you figure out what the cause was?