This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP-EXP432E401Y: Calendar Value not being Set correctly in Hibernation RTC module

Part Number: MSP-EXP432E401Y

Hi,

I am trying to set the RTC value however the tm_year value is being written wrong into the RTC. I place a value of 20 into tmYear for my variable and use HibernateCalendarSet(), however I check using HibernateCalendarGet()  and it showing a value of 48 as the year

g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_MAIN | SYSCTL_OSC_INT |SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 16000000);

void rtcSetup(tm *currentTime)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
tm matchCalendar;
matchCalendar.tm_mday = 0xFF;
matchCalendar.tm_min = 0xFF;
matchCalendar.tm_sec = 0x00;
matchCalendar.tm_hour = 0xFF;


tm calendar;
calendar.tm_year = 20;


HibernateEnableExpClk(g_ui32SysClock );
SysCtlDelay((g_ui32SysClock/3));
HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE );
HibernateRTCEnable();
HibernateCounterMode(HIBERNATE_COUNTER_24HR);
HibernateCalendarSet(&calendar);
HibernateCalendarMatchSet(0, &matchCalendar);

tm updatedCalendar 

HibernateCalendarGet(&updatedCalendar );
HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0);

IntEnable(INT_HIBERNATE);
}

  • It looks like CalendarSet expects tm_year to have a year relative to 1900. That is actually the convention for struct tm, so it's not too surprising. Try setting it to 120.

    From hibernate.c (line 1460 in my copy):

            ui32Date = ((psTime->tm_mday << HIB_CAL1_DOM_S) |
                        ((psTime->tm_mon + 1) << HIB_CAL1_MON_S) |
                        (psTime->tm_wday << HIB_CAL1_DOW_S) |
                        ((psTime->tm_year - 100) << HIB_CAL1_YEAR_S));

  • Yes I just noticed that however the compensate by adding a year when you get the year, I adjusted it and it still gives me a decimal value of 48.

  • I'm not quite sure I understand what you adjusted. The 48 comes from (20-100)=(-80)=0xB0, which is masked to 7 bits (YEAR field) to give 0x30=48.

    By setting tm_year=20, you're asking the RTC to set the calendar year to 1920, but the RTC can't express that since the YEAR field is too small. (Yes, the library could be a bit more graceful about that.) To request year 2020, set tm_year=(2020-1900)=120.

**Attention** This is a public forum