DS3231 ALARM

Post and discuss new components that you have created.
max.tisc
Posts: 55
http://meble-kuchenne.info.pl
Joined: Thu Dec 10, 2020 5:40 pm
Been thanked: 5 times

DS3231 ALARM

Post by max.tisc »

Good morning
I am doing tests with the HW-04 board that mounts a DS3231, what I can do with FC9 is read and write date and time correctly and even after many attempts (as it seems to me that it is not explained anywhere) the SQW output by varying the frequency, what I am unable to do and the most important thing is to activate the alarm function, do you have any information on how to do it?

turning on youtube I found this video on DS3231, did he or you create the component?
I tried to load it on FC9 but it doesn't see it, maybe only FC6 works
https://www.youtube.com/watch?v=J_KvLvl ... l=ElekVlog

thank you

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 video isn't mine - but I did write a DS3231 component that supports alarms - see https://www.matrixtsl.com/mmforums/view ... lit=ds3231 - it was a while ago so it doesn't use transactions for i2c which would cause issues on some MCUs - but I can modify / let you have the source if you'd like to play....

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 mnfisher
thanks for your help, I should activate the alarms for waking up the micro, I hope you can help me

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 »

I'm not familiar with the HW-04 board so details of 'sleep' may be different...
When do you want to wake (daily alarm / interval etc)

A simple example
DS3231.fcpx
(5.59 KiB) Downloaded 169 times
rtc_test1.fcfx
(13.8 KiB) Downloaded 182 times
You'll need to download the component (fcpx) file and point FC to it (GlobalSettings->Locations->Search for components in->)

I used an Arduino Nano... General setup should be similar. RTC is connected to SDA and SCL and the SQW pin connected to a pin that can wake the MCU using an interrupt. I used D2 on the Arduino. If using a breakout board it will have pull-up resistors on it for the i2c - if not you might need to add them.

I output time date and temperature to UART - you might use a different display method.

Here I use alarm2 and output every minute (when seconds are 0) (the flags are defined in the datasheet for the DS3231) (No comment in the component - my bad)

Table 2. Alarm Mask Bits
DY/DT ALARM 1 REGISTER MASK BITS (BIT 7) ALARM RATE
A1M4 A1M3 A1M2 A1M1
X 1 1 1 1 Alarm once per second
X 1 1 1 0 Alarm when seconds match
X 1 1 0 0 Alarm when minutes and seconds match
X 1 0 0 0 Alarm when hours, minutes, and seconds match
0 0 0 0 0 Alarm when date, hours, minutes, and seconds match
1 0 0 0 0 Alarm when day, hours, minutes, and seconds match
DY/DT ALARM 2 REGISTER MASK BITS (BIT 7) ALARM RATE
A2M4 A2M3 A2M2
X 1 1 1 Alarm once per minute (00 seconds of every minute)
X 1 1 0 Alarm when minutes match
X 1 0 0 Alarm when hours and minutes match
0 0 0 0 Alarm when date, hours, and minutes match
1 0 0 0 Alarm when day, hours, and minutes match

Note that after the alarm 'signal' - it must be cleared before it will fire again (using CheckAlarm)

The delay after the outputs allows the write to UART to finish before sleeping the MCU (otherwise the "\r\n" is 'lost')

The component does use 'byte mode' i2c - if the MCU are using doesn't support this then it is fairly easy to modify (SendByte(s) and ReadByte(s) need changing)

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 mnfisher
nice component nice job, I would like to test it but the properties of the I2C connections and the Baud rate are not displayed and I cannot test it, can you do something?
Attachments
Cattura.PNG
Cattura.PNG (45.75 KiB) Viewed 4312 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 »

Try:
DS3231.fcpx
(6.3 KiB) Downloaded 184 times

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

Re: DS3231 ALARM

Post by max.tisc »

thank you,
I copied the file and now the properties appear, but it does not compile from error at point 2/7, same prg with original FC component no error
Attachments
CMakeLists.txt
(39.66 KiB) Downloaded 158 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 »

I'll try with an esp32. The old component was compiled with v8 which might make a difference?

Can you post/pm your code - and I'll see if I can get it compile smoothly..

Martin

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

Re: DS3231 ALARM

Post by max.tisc »

sorry I saw your message late, the DS3231 component is in the center of the 2D panel cross, unfortunately it is not displayed correctly
thank you
Attachments
ESP32_RTC_DS3231_2.fcfx
(46.11 KiB) Downloaded 164 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 »

Okay - I modified the couple of places that the esp32 compiler was complaining about (it is very picky!)
The component doesn't simulate or display nicely on the 2d panel (if anyone would like to assist?) I will convert it to use transaction i2c handling tomorrow... then it should work on the chips that don't support 'byte' handling (ARM and possibly others??)
DS3231.fcpx
(5.8 KiB) Downloaded 175 times
So your code should now compile okay.

As an aside - the esp32 has an inbuilt clock that can be used to wake from light/deep sleep there is some sample code at https://flowcode.co.uk/forums/viewtopic ... sp32+sleep

Martin

Post Reply