DS3231 revisited
Posted: Wed Jun 24, 2020 11:16 pm
I'm not usually in favour of re-inventing the wheel - but I noticed a comment about DS3231 alarms in the forum recently..
I alo wanted an interrupt using alarm 2 (hours and minutes match) - to wake a low power logger (so this can occur on the battery backup of the RTC and wake an ATTiny) (Note I used a 1s SQW - though this required the RTC clock to be powered and a PP3 lasted ~24hours not good)
So - without checking the datasheet - anyone know the correct values for SQWandINTControl.. Okay - you can check the datasheet. Still struggling?
So I knocked together a simple 'talk to the RTC' proto-component. I was aslo slightly dissatisified with the current syntax - but seeking suggestions here.
I came up with
Set/GetTime(hms[3]) (Where hms is a 3 byte array with hours, mins.... as hms[0] hms[1] etc)
Set/GetAlarm1(hms[3]) and Get/SetAlarm2[fm[2]) (or Get/SetAlarm(hm(s), alarmNo)
An alternative for Set is SetTime(hrs, mins, secs) - unfortunately this is not so easy for retrieving multiple values, and I like the idea of get and set being symetrical.
And I'd anticipate - Get/SetDate(dmy[]) for RTC and Alarm1
GetTime/Datestring
SetAlarmFlags
SetAlarm1Flags(flags) and SetAlarm2Flags(flags) or SetAlarmFlags(alarm, flags) - any thoughts?
I added GetTemperature().
I'm hoping the component will save a fair bit of memory compared to the current (which seems based on an Arduino one - it seems to have all the i2c code in every function - rather than a Get/SendBytes(addr, n, data[]) - I'm aiming for ATTinies here.
Any other ideas / suggestions (currently I have a SetMode(12h = true) to set 12h mode rather than passing this as an argument - and set bit 7 of the hours for PM? This seems slightly clumsy - and I also thought of only supporting 24hour mode, or a PM flag passed to the Set macros?
Martin
I alo wanted an interrupt using alarm 2 (hours and minutes match) - to wake a low power logger (so this can occur on the battery backup of the RTC and wake an ATTiny) (Note I used a 1s SQW - though this required the RTC clock to be powered and a PP3 lasted ~24hours not good)
So - without checking the datasheet - anyone know the correct values for SQWandINTControl.. Okay - you can check the datasheet. Still struggling?
So I knocked together a simple 'talk to the RTC' proto-component. I was aslo slightly dissatisified with the current syntax - but seeking suggestions here.
I came up with
Set/GetTime(hms[3]) (Where hms is a 3 byte array with hours, mins.... as hms[0] hms[1] etc)
Set/GetAlarm1(hms[3]) and Get/SetAlarm2[fm[2]) (or Get/SetAlarm(hm(s), alarmNo)
An alternative for Set is SetTime(hrs, mins, secs) - unfortunately this is not so easy for retrieving multiple values, and I like the idea of get and set being symetrical.
And I'd anticipate - Get/SetDate(dmy[]) for RTC and Alarm1
GetTime/Datestring
SetAlarmFlags
SetAlarm1Flags(flags) and SetAlarm2Flags(flags) or SetAlarmFlags(alarm, flags) - any thoughts?
I added GetTemperature().
I'm hoping the component will save a fair bit of memory compared to the current (which seems based on an Arduino one - it seems to have all the i2c code in every function - rather than a Get/SendBytes(addr, n, data[]) - I'm aiming for ATTinies here.
Any other ideas / suggestions (currently I have a SetMode(12h = true) to set 12h mode rather than passing this as an argument - and set bit 7 of the hours for PM? This seems slightly clumsy - and I also thought of only supporting 24hour mode, or a PM flag passed to the Set macros?
Martin