Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ard2pmod DS3231demo DS3231demo_COM_Port_Output MAXREFDES99_RTC_Display ... more
Diff: ds3231.cpp
- Revision:
- 7:0551d7e7c13f
- Parent:
- 6:e8850ad15893
- Child:
- 10:3b55ed3f71d3
--- a/ds3231.cpp Sat Nov 29 20:22:12 2014 +0000
+++ b/ds3231.cpp Mon Dec 01 20:31:03 2014 +0000
@@ -128,7 +128,7 @@
}
data_length++;
- //Test for good data.
+ //Make sure data is within range.
if((time.seconds > 59) || (time.minutes > 59) || (time.hours > max_hour))
{
return(1);
@@ -174,8 +174,18 @@
data[data_length++] = uchar_2_bcd(calendar.month);
data[data_length++] = uchar_2_bcd(calendar.year);
- //users responsibility to make sure calendar is logical
- return(write(w_adrs,(const char*) data, data_length));
+ //Make sure data is within range.
+ if(((calendar.day < 1) || (calendar.day > 7)) ||
+ ((calendar.date < 1) || (calendar.date > 31)) ||
+ ((calendar.month < 1) || (calendar.month > 12)) ||
+ (calendar.year > 99))
+ {
+ return(1);
+ }
+ else
+ {
+ return(write(w_adrs,(const char*) data, data_length));
+ }
}
@@ -320,8 +330,10 @@
mask_var = 0;
}
- //Test for good data.
- if((alarm.seconds > 59) || (alarm.minutes > 59) || (alarm.hours > max_hour) || (alarm.day > 7) || (alarm.date > 31))
+ //Make sure data is within range.
+ if((alarm.seconds > 59) || (alarm.minutes > 59) || (alarm.hours > max_hour) ||
+ ((alarm.day < 1) || (alarm.day > 7)) ||
+ ((alarm.date < 1) || (alarm.date > 31)))
{
return(1);
}
DS3231 Real Time Clock RTC Integrated Crystal, 2 Alarms, Extremely Accurate High Precision