If your module has DS3231M chip then according to datasheed this modification can only generate 1Hz signal on INT/SQW pin (3) and 32768Hz on 32kHz pin(1). I have several DS3231M's and checked it.
If your module has DS3231SN chip: I had a similar issue recently. Got 10 pcs of DS3231SN from ali. Soldered one IC to my board and discovered this problem. Luckily I had ZIF SO16 to DIP adapter and built a test-board, connected it to oscilloscope and tested all of them. Only 4 pcs of 10 was able to generate different signals (1024Hz, 4096Hz etc.) on SQW pin according to datashet. Also they generated stable 32768 Hz signal on 32KHz pin (pin 1).
Other 6(also marked as DS3231SN) gave only 1 Hz signal on SQW pin, all of them produced signal on 32 kHz pin (one IC generated about 35 kHz), one IC generated floating frequency signal on SQW pin (around 1500 Hz and it cant be changed). I think it's low quality fake IC's.
Answer from Paul on Stack OverflowDS3231 Alarm Clock with SQW Interrupt
How to set up one second interrupt/ISR for ds3231 RTC - Arduino Stack Exchange
DS3231 RTC module SQW pin: High/low for extended time?
Alarm interrupt and square wave.
This answer addresses the original question of why the interrupts didn't work. I happened to have a DS3231 lying around so I made up a test.
Interrupt vs pin number
First, this is wrong in your code:
attachInterrupt(rtcTimerIntPin, rtc_interrupt, RISING);
You need an interrupt number, not a pin number. This is correct:
attachInterrupt (digitalPinToInterrupt (rtcTimerIntPin), rtc_interrupt, CHANGE);
I also made it a CHANGE interrupt so you get both the rising and falling pulse.
Pull-up resistor
Next, the 1 Hz output needs a pull-up resistor, so you should add that or make it INPUT_PULLUP like this:
pinMode (rtcTimerIntPin, INPUT_PULLUP);
Testing
I used this library from Adafruit.
Adapting one of their examples, and putting in your interrupt code (with my modifications), it worked!
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
const byte rtcTimerIntPin = 2;
volatile byte flag = false;
void rtc_interrupt ()
{
flag = true;
} // end of rtc_interrupt
void setup () {
Serial.begin(115200);
while (!Serial); // for Leonardo/Micro/Zero
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// enable the 1 Hz output
rtc.writeSqwPinMode (DS3231_SquareWave1Hz);
// set up to handle interrupt from 1 Hz pin
pinMode (LED_BUILTIN, OUTPUT);
pinMode (rtcTimerIntPin, INPUT_PULLUP);
attachInterrupt (digitalPinToInterrupt (rtcTimerIntPin), rtc_interrupt, CHANGE);
}
void loop () {
if (flag) {
digitalWrite(LED_BUILTIN, HIGH); // flash the led
delay(100); // wait a little bit
digitalWrite(LED_BUILTIN, LOW); // turn off led
flag = false; // clear the flag until timer sets it again
}
}
Use this DS3231 library. It has a method to set the squarewave RTC.squareWave(SQWAVE_1_HZ)



