DS3231 ALARM

Post and discuss new components that you have created.
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: DS3231 ALARM

Post 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 182 times

max.tisc
Posts: 55
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 5 times

Re: DS3231 ALARM

Post by max.tisc »

Hi Martin
I have an arduino nano available, today I will try your program
thank you

max.tisc
Posts: 55
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 5 times

Re: DS3231 ALARM

Post 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
Attachments
IMG_20220601_190454.jpg
IMG_20220601_190454.jpg (86.39 KiB) Viewed 4434 times
IMG_20220601_190545.jpg
IMG_20220601_190545.jpg (107.58 KiB) Viewed 4434 times
ds3231 alarm.fcfx
(11.5 KiB) Downloaded 178 times

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: DS3231 ALARM

Post 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 193 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

max.tisc
Posts: 55
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 5 times

Re: DS3231 ALARM

Post 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
Attachments
vid-20220602-110747_TQ6vqXRg (2).zip
(3.93 MiB) Downloaded 182 times

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: DS3231 ALARM

Post 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

max.tisc
Posts: 55
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 5 times

Re: DS3231 ALARM

Post 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.
Attachments
NANO_ds3231 alarm.fcfx
(16.2 KiB) Downloaded 182 times

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: DS3231 ALARM

Post 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

max.tisc
Posts: 55
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 5 times

Re: DS3231 ALARM

Post by max.tisc »

ok, sorry now I understand
thank you

kaqkk007
Posts: 26
Joined: Sat Feb 04, 2023 1:09 pm
Has thanked: 2 times
Been thanked: 1 time

Re: DS3231 ALARM

Post 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 ?

Post Reply