Deadon RTC DS3234 control register returns 0 when no battery installed

I’m using the Deadon RTC DS3234 breakout with weird results for the 0x0E control register which returns 0 when queried, even after being set to 0b01000000.

I didn’t see anywhere in the DS3234 datasheet about returning 0 from the 0x0E control register if the battery isn’t installed. The other control register is fine without the battery. 0x0E occasionally returns the correct value but 90% of the time it returns 0 if the battery isn’t installed.

I’m using a NodeMCU ESP8266 12-E, SPI, with 3.3V on Vcc and the battery is at 3.06V. No battery = no data from 0x0E register.

I moved SQW to GPIO10 and it was ok. Then I moved SQW back to D2 and the 0x8E control register could not be written to and the 0x0F register always returned 0 even though it’s not zero (it returned 200 at one point).

After a few loops, the 0x0E register starts to return the previous value when I turned off the square wave while GPIO10 was the interrupt pin. When I set D2 as the interrupt pin the register couldn’t be written to so the SQW remained off.

It seems to be related to interrupts. If I put the interrupt back on GPIO10, I can set the register just fine and the register reads are all showing expected data apart from the 0x0F register which intermittently returns zero but the main 0x0E register is stable.

I’m wondering whether the pin used for interrupt needs to be disabled somehow when a new pin is used as an interrupt. e.g. I’d left GPIO10 as pinMode(10, INPUT_PULLUP); which I assume was interfering with the new interrupt defined as pinMode(4, INPUT_PULLUP);

i.e. if moving from GPIO10 to GPIO4:

detachInterrupt(digitalPinToInterrupt(10));

and vice versa. However doing that doesn’t help stabilise the register reads. 0x0F is still mostly zero.

I think it’s all down to the interrupt. Not enabling the interrupt and all the register reads are fine. However, that makes no sense as to get it to write to the control register I had to move the SQW back to the GPIO pin that was the interrupt pin when the SQW was turned off in the control register. This seems to suggest interrupts are preserved across restarts but not enabling in setup() suggests they are not preserved across restarts.

void timeInterruptFunction() {

timeTriggers++;

if (timeTriggers < 5) {

return;

}

timeTriggers = 0;

readSensors = true;

}

void loop() {

if (readSensors) {

…unstable register reads…

}

}

not enabling the interrupt in setup() and everything is fine in the register reads in loop()

turns out I was enabling the interrupt on the rising edge but the datasheet confirmed it’s an active low SQW. The following solved the problem:

pinMode(_interruptPin, INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(_interruptPin), _sqwFunction, FALLING);