Go Down

Topic: Problems with DS3231 Library (Read 1 time) previous topic - next topic

PaulS

It seems easy enough to test. Create a variable. Set the bits for alarm 1. Set the bits for alarm 2. Call the setA1Time() method. Call the setA2Time() method. Call the getA1Time() method. Check the flags for both alarms. Call the getA2Time() method. Check the flags for both alarms.

KirAsh4

That's exactly how I figured out that there's a problem.  I created two different variables in my sketch, ARLM1 and ALRM2, with different bits in each (one had 0b1111 and the other 0b100) and passed those variables to setA1Time and setA2Time.  Setting A2 never takes the AlarmBits into account.  When I read things back, A2 reported its bits as 0b1111 (or whatever A1 is set as.)

KirAsh4

The only other thing I can think of attempting is modifying the .cpp file to use two different variables, for example A1AlarmBits and A2Alarmbits as opposed to one single one.  But I still can't figure out why it's not working right now, as written.

KirAsh4

Anyone else feel like taking a stab at this before I start my attempt at hacking the library, hoping I know what I'm actually doing and figure out what's going on?

KirAsh4

Ok, having changed the variables in the different routines to specifically say Alarm1Bits and Alarm2Bits did not make a difference.  Now what I'm seeing is, when I try to read the data back, the bits for Alarm1 get set, but Alarm 2 remains at 0.  Nothing's set.  So, I'm still stuck.

The relevant lines in my sketch that sets the alarms is:
Code: [Select]
      Clock.setA1Time(Clock.getDoW(), Clock.getHour(h12, PM), Clock.getMinute(), 30, ALRM1_SET, true, false, false);
      Clock.setA2Time(Clock.getDate(), Clock.getHour(h12, PM), Clock.getMinute(), ALRM2_SET, false, false, false);
      // Turn alarms on
      Clock.turnOnAlarm(1);
      Clock.turnOnAlarm(2);


The variables ALRM1_SET and ALRM2_SET are 0b1000 and 0b111 respectively.  Alarm1 is set properly.  Alarm2 returns 0 when I read the bits back.  The relevant part in the .cpp is:
Code: [Select]
void DS3231::setA1Time(byte A1Day, byte A1Hour, byte A1Minute, byte A1Second, byte Alarm1Bits, bool A1Dy, bool A1h12, bool A1PM) {
// Sets the alarm-1 date and time on the DS3231, using A1* information
byte temp_buffer;
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(0x07); // A1 starts at 07h
// Send A1 second and A1M1
Wire.write(decToBcd(A1Second) | ((Alarm1Bits & 0b00000001) << 7));
// Send A1 Minute and A1M2
Wire.write(decToBcd(A1Minute) | ((Alarm1Bits & 0b00000010) << 6));
// Figure out A1 hour
if (A1h12) {
// Start by converting existing time to h12 if it was given in 24h.
if (A1Hour > 12) {
// well, then, this obviously isn't a h12 time, is it?
A1Hour = A1Hour - 12;
A1PM = true;
}
if (A1PM) {
// Afternoon
// Convert the hour to BCD and add appropriate flags.
temp_buffer = decToBcd(A1Hour) | 0b01100000;
} else {
// Morning
// Convert the hour to BCD and add appropriate flags.
temp_buffer = decToBcd(A1Hour) | 0b01000000;
}
} else {
// Now for 24h
temp_buffer = decToBcd(A1Hour);
}
temp_buffer = temp_buffer | ((Alarm1Bits & 0b00000100)<<5);
// A1 hour is figured out, send it
Wire.write(temp_buffer);
// Figure out A1 day/date and A1M4
temp_buffer = ((Alarm1Bits & 0b00001000)<<4) | decToBcd(A1Day);
if (A1Dy) {
// Set A1 Day/Date flag (Otherwise it's zero)
temp_buffer = temp_buffer | 0b01000000;
}
Wire.write(temp_buffer);
// All done!
Wire.endTransmission();
}

void DS3231::setA2Time(byte A2Day, byte A2Hour, byte A2Minute, byte Alarm2Bits, bool A2Dy, bool A2h12, bool A2PM) {
// Sets the alarm-2 date and time on the DS3231, using A2* information
byte temp_buffer;
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(0x0b); // A1 starts at 0bh
// Send A2 Minute and A2M2
Wire.write(decToBcd(A2Minute) | ((Alarm2Bits & 0b00010000) << 3));
// Figure out A2 hour
if (A2h12) {
// Start by converting existing time to h12 if it was given in 24h.
if (A2Hour > 12) {
// well, then, this obviously isn't a h12 time, is it?
A2Hour = A2Hour - 12;
A2PM = true;
}
if (A2PM) {
// Afternoon
// Convert the hour to BCD and add appropriate flags.
temp_buffer = decToBcd(A2Hour) | 0b01100000;
} else {
// Morning
// Convert the hour to BCD and add appropriate flags.
temp_buffer = decToBcd(A2Hour) | 0b01000000;
}
} else {
// Now for 24h
temp_buffer = decToBcd(A2Hour);
}
// add in A2M3 bit
temp_buffer = temp_buffer | ((Alarm2Bits & 0b00100000)<<2);
// A2 hour is figured out, send it
Wire.write(temp_buffer);
// Figure out A2 day/date and A2M4
temp_buffer = ((Alarm2Bits & 0b01000000)<<1) | decToBcd(A2Day);
if (A2Dy) {
// Set A2 Day/Date flag (Otherwise it's zero)
temp_buffer = temp_buffer | 0b01000000;
}
Wire.write(temp_buffer);
// All done!
Wire.endTransmission();
}


Ideas anyone?  I really need to get this second alarm working for my project.

Go Up