Hi,
I just cannot get to store the alarm time in the DS3231 flash memory.
The getA1Time routine is not returning the data I previously ‘stored’.
Any help is appreciated.
TIA
#include <DS3231.h>
/* Clock chip settings */
DS3231 Clock;
byte ADay, AHour, AMinute, ASecond, ABits; // Alarm variables
bool ADy, A12h, Apm; // Alarm variables
// setting AL1 and AL2 registers
// http://forum.arduino.cc/index.php?topic=168421.0
#define ALRM1_MATCH_HR_MIN_SEC 0b1000 // when hours, minutes, and seconds match
byte ALRM1_SET = ALRM1_MATCH_HR_MIN_SEC;
#define ALRM2_MATCH_HR_MIN 0b100 // when hours and minutes match
byte ALRM2_SET = ALRM2_MATCH_HR_MIN;
// Set AlarmBits, ALRM2 first, followed by ALRM1
void setup()
{
Serial.begin(9600);
delay(50);
/* set alarm1 time to 17:15*/
AHour = byte(17);
AMinute = byte(15);
setAlarms(); // store alarm variables NOT WORKING
Clock.getA1Time(ADay, AHour, AMinute, ASecond, ABits, ADy, A12h, Apm); // read alarm stored values
}
void loop()
{
Serial.print(AHour, DEC);
Serial.print(" ");
Serial.println(AMinute, DEC);
}
void setAlarms() {
// Set AlarmBits, ALRM2 first, followed by ALRM1
int AlarmBits = ALRM2_SET;
AlarmBits <<= 4;
AlarmBits |= ALRM1_SET;
// set both alarms to :00 and :30 seconds, every minute
// Format: .setA*Time(DoW|Date, Hour, Minute, Second, 0x0, DoW|Date, 12h|24h, am|pm)
// | | | |
// | | | +--> when set for 12h time, true for pm, false for am
// | | +--> true if setting time based on 12 hour, false if based on 24 hour
// | +--> true if you're setting DoW, false for absolute date
// +--> INTEGER representing day of the week, 1 to 7 (Monday to Sunday)
//
Clock.setA1Time(Clock.getDoW(), AHour, AMinute, 0, AlarmBits, false, false, false);
Clock.setA2Time(Clock.getDate(), AHour, AMinute, AlarmBits, false, false, false);
}