DS3231 Illogical time and date

Hi All,

I have been coding Arduino for some time now, but I recently encountered a problem that I hope the forum can help me with.

For the DS3231 RTC from MAXIM, is there a way to check is the date set is illogical (e.g. 30 of February)?

The datasheet states that: "Illogical time and date entries result in undefined operation".

I hope that there is a possibility for QC'ing that the set data is logical.

Best regards,

Rune Jacobsen

You have to ensure that you don't set the date to an illogical value. After that, the date will be correct. To do that, your sketch will need to detect a leap year and check for the correct number of days in February and also check for the correct number of days in the remaining months. You should also check that you aren't setting the time incorrectly - e.g. 25:62:01, which might set the time to a logical value but probably not the correct one.

Pete

Dear Pete,

Thanks for your reply.

It is of cause possible to let the Arduino test if the date is illegal before setting the DS3231. This does however require some overhead (i.e. programming the allowed calendar into the Arduino will take up SRAM and FLASH space).

As the DS3231 already have a calendar that works till 2099, I hope to use this without adding another calendar in the Arduino.

Best regards,

Rune Jacobsen

The key here is what the data sheet says - "Illogical time and date entries result in undefined operation". That means that if you don't validate the data before setting the chip, the results will be undefined - it may roll over to a correct date or simply keep counting to Feb 31, Feb 32 etc. It is not specified (and may vary depending on exactly where it starts) so the answer is that you need to validate the date BEFORE setting the chip. You don't need a full calendar, an array of months with the maximum day (and you need to determine if it is leapyear) would cover the months, hours must be less than 25, minutes/seconds less than 60.

One of the first rules of good design is to study the data sheet then don't violate any of the specifications. My preference is to stay well away from the limits when possible. You will be much happier with a well behaved project down the road. Really - it is worth the extra effort to get it right in the long run. :)