RTC drivers fix (#259)
This commit is contained in:
parent
8ef476c71f
commit
98de5e573a
3 changed files with 17 additions and 16 deletions
|
@ -25,7 +25,7 @@ void user_init (void)
|
|||
// setup datetime: 2016-10-09 13:50:10
|
||||
struct tm time = {
|
||||
.tm_year = 2016,
|
||||
.tm_mon = 10,
|
||||
.tm_mon = 9, // 0-based
|
||||
.tm_mday = 9,
|
||||
.tm_hour = 13,
|
||||
.tm_min = 50,
|
||||
|
@ -37,7 +37,8 @@ void user_init (void)
|
|||
{
|
||||
ds1307_get_time(&time);
|
||||
|
||||
printf ("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
|
||||
printf("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon + 1,
|
||||
time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
|
||||
|
||||
for (uint32_t i = 0; i < 1000; i++)
|
||||
sdk_os_delay_us(500);
|
||||
|
|
|
@ -78,14 +78,14 @@ void ds1307_get_time(struct tm *time)
|
|||
if (buf[2] & HOUR12_BIT)
|
||||
{
|
||||
// RTC in 12-hour mode
|
||||
time->tm_hour = bcd2dec(buf[2] & HOUR12_MASK);
|
||||
time->tm_hour = bcd2dec(buf[2] & HOUR12_MASK) - 1;
|
||||
if (buf[2] & PM_BIT)
|
||||
time->tm_hour += 12;
|
||||
}
|
||||
else time->tm_hour = bcd2dec(buf[2] & HOUR24_MASK);
|
||||
time->tm_wday = bcd2dec(buf[3]) - 1;
|
||||
time->tm_mday = bcd2dec(buf[4]);
|
||||
time->tm_mon = bcd2dec(buf[5]);
|
||||
time->tm_mon = bcd2dec(buf[5]) - 1;
|
||||
time->tm_year = bcd2dec(buf[6]) + 2000;
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ bool ds3231_getTime(struct tm *time)
|
|||
time->tm_min = bcdToDec(data[1]);
|
||||
if (data[2] & DS3231_12HOUR_FLAG) {
|
||||
/* 12H */
|
||||
time->tm_hour = bcdToDec(data[2] & DS3231_12HOUR_MASK);
|
||||
time->tm_hour = bcdToDec(data[2] & DS3231_12HOUR_MASK) - 1;
|
||||
/* AM/PM? */
|
||||
if (data[2] & DS3231_PM_FLAG) time->tm_hour += 12;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue