UNO R3 interrupt from DS3231 RTC problem

I am having a problem with interrupts, more specifically with the ISR. I am working with a DS3231 RTC module with an Arduino UNO R3. The program intent is to drive a motor with a relay three times during the day. I am using the alarm function on the RTC to trigger the motor activity at the appropriate time. I am able to program the RTC alarm registers with no issues and the alarm will trigger at the correct time The alarm signal (INT/SQW) is connected to Arduino pin 2 and the interrupt is enabled with FALLING mode

My original test for the ISR was a simple “Serial.print” command, which worked as intended. I modified the ISR to be able to write to the RTC using the wire library. When the alarm triggered and the ISR called, it started to execute the print statement I left in but hung up. I read in another forum on interrupts that the ISR should be very short, also that there might be issues with wire library commands in the ISR. I had the ISR call another routine which did get called but hung up in the same manor.

I am noticing that the interrupt pin on the RTC is still active (low) so I am assuming that it still sees the interrupt and that is causing problems. I have tried adding noInterrupts as the first statement in the ISR but that has not improved anything, It appears that any command/statement issues in the ISR works fine until I want the write to the RTC, then things hang, no more code execution.

I know this is a long description, I just wanted to get as much information out as I could. I am not Shure how to clear the interrupt as it appears to me too be at least part of the issue. I appreciate any help or suggestion.

Make your ISR lightweight. One way to make them lightweight is to enter the ISR, set a flag, exit the ISR... then inside your main program, test the flag. Do not put loops or Serial.print() or data transfers in the ISR... too much processing time.

No. If the interrupt mode is set for FALLING, the active low signal will not retrigger the interrupt.

the ISR works fine until I want the write to the RTC, then things hang, no more code execution.

The i2c transfers rely on interrupts, and interrupts are disabled when the ISR is executed. Serial output is the same, but it is buffered and appears to work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.