Page 3 of 3

Re: DS3231 ALARM

Posted: Tue May 31, 2022 10:34 pm
by mnfisher
There is a delay in the interrupt handler.. This is a quite probably causing the problem... See -> https://www.flowcode.co.uk/forums/viewt ... 0&start=30)

I did a simple test where the interrupt just toggles the LED (so every minute with the settings as is) and all seems well. Note I use an Arduino Nano with the ds3231 powered by a2 and a3 - if you plug the board I have in with sda by a4 and scl to a5 - this works well for the board I have. I've used the interrupt on d3 as I have the board wired for another test using d2. I have an LED attached to d4.
If you want the LED to just flash for 200ms - set a flag in the interrupt handler and handle the 'flash' in the main loop.

I also tried using alarm 1 and a 1s flash rate - this didn't work, although setting the SQW to 1Hz did. I'll see if I can fix this.

Martin
ds3231 alarm.fcfx
(11.5 KiB) Downloaded 184 times

Re: DS3231 ALARM

Posted: Wed Jun 01, 2022 10:45 am
by max.tisc
Hi Martin
I have an arduino nano available, today I will try your program
thank you

Re: DS3231 ALARM

Posted: Wed Jun 01, 2022 6:23 pm
by max.tisc
Hi Martin
I tried your program but the led does not show signs of life, the only things I changed are the LED port because on my nano there is already an LED on B5 and I feed the DS with the 3.3V coming out of the board, if I disconnect pin interrupt 1 (D3) the LED flashes very quickly so as long as everything is correct, I tried with 2 DS3231 cards with the same result
thanks

Re: DS3231 ALARM

Posted: Wed Jun 01, 2022 6:47 pm
by mnfisher
All looks okay (and the inbuilt LED on B5 (pin d13) - should light as well. Assuming you have a current limiting resistor in place - the LED shouldn't 'flash rapidly' if you disconnect the interrupt pin (it should just 'light' and then turn-off on the next interrupt (although a 'floating' pin might generate random interrupts?) The code just lights the LED with a 1 minute on and then 1 minute off cycle (after a delay of up to 60s - depending on start time).

It is possible for the ds3231 to be in a 'crashed' or 'inactive' state (your previous code - an interrupt could occur during a attempt to read the time - which might cause i2c errors (due to the 200ms pause) and result in this state)

If the rtc is in this error state - then if you read the time it will display as 11:11:11 (if I remember rightly) - try reading the time and outputting it to the UART... You'll need to use a terminal program (I use 'putty' from https://www.putty.org/)

It can be 'reset' by setting the time (or try RestartRTC and then set time).
ds3231 alarm.fcfx
(15.14 KiB) Downloaded 194 times
Another bug - if you enable the SQW then this value is 'sticky' - with no way to disable it. Initialise probably needs to clear this.

Martin

Re: DS3231 ALARM

Posted: Thu Jun 02, 2022 10:46 am
by max.tisc
Hi Martin
I added the UART and from the video you see that the time runs regularly, at the end of the minute on the LED L there is no change of state, I also added a RestartRTC but it has no effect

Re: DS3231 ALARM

Posted: Thu Jun 02, 2022 11:49 am
by mnfisher
The answer is simpler than we thought....

Need to call SetAlarm(2, true) to turn alarm 2 on (setting the flags doesn't enable the alarm.)... Note these values are 'sticky' due to the battery backup - so will survive restarts etc.
I've added a 'disable' option to the EnableSQW. Any other thoughts - then I'll re-upload...

Martin

Re: DS3231 ALARM

Posted: Sun Jun 05, 2022 5:09 pm
by max.tisc
Hi Martin
I did this test by reading your advice, I added an I2C component and then I went to write the bit 1 to 1 on register 0X0E to enable alarm 2 and now I see the impulses that activate and deactivate the LED every minute, I have turned off and turned on several times (without backup battery) and it always works, of course this is not the ideal solution and it should be integrated inside the component and I don't know how to do this, even if I would love to learn how to create the components I need.

Re: DS3231 ALARM

Posted: Sun Jun 05, 2022 6:03 pm
by mnfisher
SetAlarm(2, true) does this - see my previous message about forgetting to turn the alarm on (sorry). The value is saved by the rtc so once on it tends to stay on..

Martin

Re: DS3231 ALARM

Posted: Mon Jun 06, 2022 8:52 pm
by max.tisc
ok, sorry now I understand
thank you

Re: DS3231 ALARM

Posted: Sun Feb 04, 2024 6:49 pm
by kaqkk007
I just did a component update again (requested by the program) thanks to the ds3231 not allowing the SDA-SCL to be rewritten to another outlet , but I am already routine so I reset the rtc component with two updates so the thing is solved (can be set ) but whether it works will only be found out in a few days when I start trying . Why do the updates succeed like this ?