Skip to content

Commit

Permalink
fix for RTC conversion to unix time.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mcgowan committed Oct 1, 2015
1 parent 44d3c5e commit 4a61d52
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions hal/src/stm32f2xx/rtc_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,6 @@ void HAL_RTC_Configuration(void)
}
}

uint8_t BCD2Binary(uint8_t bcd)
{
return ((bcd & 0xF0)*10) + (bcd&0xF);
}

uint8_t Binary2BCD(uint8_t bcd)
{
return bcd%10 + (bcd/10)*16;
}

time_t HAL_RTC_Get_UnixTime(void)
{
RTC_TimeTypeDef RTC_TimeStructure;
Expand All @@ -192,7 +182,7 @@ time_t HAL_RTC_Get_UnixTime(void)
/* Set calendar_time date struct values */
calendar_time.tm_wday = RTC_DateStructure.RTC_WeekDay;
calendar_time.tm_mday = RTC_DateStructure.RTC_Date;
calendar_time.tm_mon = BCD2Binary(RTC_DateStructure.RTC_Month);
calendar_time.tm_mon = RTC_DateStructure.RTC_Month-1;
calendar_time.tm_year = RTC_DateStructure.RTC_Year;

return (time_t)mktime(&calendar_time);
Expand All @@ -214,7 +204,7 @@ void HAL_RTC_Set_UnixTime(time_t value)
/* Get calendar_time date struct values */
RTC_DateStructure.RTC_WeekDay = calendar_time->tm_wday;
RTC_DateStructure.RTC_Date = calendar_time->tm_mday;
RTC_DateStructure.RTC_Month = Binary2BCD(calendar_time->tm_mon);
RTC_DateStructure.RTC_Month = calendar_time->tm_mon+1;
RTC_DateStructure.RTC_Year = calendar_time->tm_year;

setRTCTime(&RTC_TimeStructure, &RTC_DateStructure);
Expand Down

0 comments on commit 4a61d52

Please sign in to comment.