I am not getting intterupt on RTC DS3231

I have a ds3231 rtc module. I am very happy with. Currently I have it working on my mega 2650 with an lcd and keypad membrane. it displays current time, date, temperature etc.

I have functions to set the time and the alarm which are working. I can read out the alarm time on the lcd set alarm time with print alarm function. First when I set the alarm, I stored the alarm figures in variables in the mega, worked fine, it got me out bed.

but ofc, when I have a power failure at night, the alarm gets resetted. So I decided to use the alarm 1 register of the rtc. setting the alarm registers was ez. But I am getting no interrupt signal on the SQW pin of the RTC.

to activate the alarm I do the following.

Wire.write(0x0E); // control register address
Wire.write(0b00000101); // put INTCON at 1 to remove pwm on the pin and allows alarm to trigger an interrupt
Wire.endTransmission(); // put A1IE at 1 to enable alarm 1 so that interrupt will happen on a match of time and alarm


Wire.write(0x07); // alarm seconde adres
Wire.write(0x00); // seconde
Wire.write(DecToBcd(alarm_minuut)); // minuten
Wire.write(DecToBcd(alarm_uur)); // uren
Wire.write(0b10000000 + DecToBcd(datum)); // datum <<< THIS is cuz; I need to make the MSB of address 0x0Ah HIGH
Wire.endTransmission(); // so that alarm is triggered only on match of seconds, minutes and hours

I connect the interrupt pin with a 4k7 R to 5V and this line should activate my ISR; attachInterrupt(5, ALARM, CHANGE);
ALARM is the ISR.

I tried everything; different interrupt pins, no pullup R, 5, alarm, FALLING, Wire.write(0x0E); Wire.write(0b0000101)// (one less 0), name it and I tried it.

Can anyone tell me what I am doing wrong?

I think I will just take alarm 2 because it has no second match, and thus one potential problem less to care about -_-.

Also I am making use of a timer library <Timer.h> idk if this can influence the interrupts??

I can't see anything obvious that you are doing wrong.

Here are some trouble shooting ideas.

1) Can you see the Alarm 1 Flag (A1F) or Alarm 2 Flag (A2F) being set in bits 0 and 1 of register 0x0F when the alarm is supposed to have triggered? If you see these flags, you can determine if there is a problem with the alarms or the external output.

2) If you enable the square wave and set it to 1Hz with RS2 and RS1, can you see it going high and low with simple digital reads of the square wave pin? You should use the 5v pull up on this pin.

I think if you can confirm items 1 and 2, then the problem will be in the mega and the interrupt routine and not the DS3231.

Check the result code of Wire.endTransmission() to be able to detect errors on the I2C interface.

And please use code tags! You should also show the rest of the code. It might be some error in there like writing to the serial interface in the interrupt handler or anything like this.

Do you use a RTC.Begin code in your sketch? If so, delete it and try again.

I found that when powering on the Arduino, the RTC.begin or similar would reset the alarm register. After deleting it, my sketch did what it had to do.