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.

CC3220SF-LAUNCHXL: What could cause a wrong RTC reading?

Part Number: CC3220SF-LAUNCHXL

I'm using the following function to read the current epoch:

time_t _GetEpoch(void)
{
    _i16 ret;
    _u8 pConfigOpt = SL_DEVICE_GENERAL_DATE_TIME;
    _u16 pConfigLen = sizeof(SlDateTime_t);

    SlDateTime_t dateTime = {0};
    ret = sl_DeviceGet(SL_DEVICE_GENERAL, &pConfigOpt, &pConfigLen, (unsigned char *) &dateTime);
    ASSERT_ON_ERROR(ret);

    struct tm t;
    time_t t_of_day;

    t.tm_year = dateTime.tm_year - 1900;
    t.tm_mon = dateTime.tm_mon - 1;
    t.tm_mday = dateTime.tm_day;
    t.tm_hour = dateTime.tm_hour;
    t.tm_min = dateTime.tm_min;
    t.tm_sec = dateTime.tm_sec;
    t.tm_isdst = -1;
    t_of_day = mktime(&t);

    UART_PRINT(0, "[SYS] struct tm: %d/%d/%d %d:%d:%d\r\n", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    UART_PRINT(0, "[SYS] time_t : %lld\r\n", t_of_day);
    return t_of_day;
}

My application will put in hibernation the MCU for a minute using:

Power_shutdown(0, 60000);

on wakeup I call the above function to read the current epoch and do something appropriate. Sometimes the reading is wrong, and interestingly enough, it will return a date in 2022, then if I read it again it will show the correct value:

[SYS] struct tm: 117/10/20 10:23:34
[SYS] time_t   : 1511173414
[SYS] Shutdown 
[SYS] struct tm: 117/10/20 10:24:41
[SYS] time_t   : 1511173481
[SYS] Shutdown 
[SYS] struct tm: 122/1/20 21:7:48
[SYS] time_t   : 1645391268                                                                                                                                                         
[SYS] Shutdown 
[SYS] struct tm: 117/10/20 10:25:40
[SYS] time_t   : 1511173540               

Of course there MUST be something wrong in my code. What could cause such a wrong RTC reading?

  • Hi,

    Does this only occur on the first read after waking u from hibernate or is the occurrence random?

    Regards,
    Charles O
  • Looking at my latests logs it seems to occur to the first reading after waking up only. But please note that might happen even after 1 s from wake up.
  • After exiting hibernation I call two times the function GetEpoch() and the results are ok. Later in the code, I call it again and the result is wrong. How does the same function returns different results from RTC?
  • Any hints? We're delaying a mass-production due to this issue. It doesn't seem an hardware one, because the next reading is correct (i.e. the RTC value is not lost) but we need your help to understand what's wrong in the code above, given that is from your examples.
  • Here my last test:

    void ApplicationTask(void)
    {
        _u8 i;
    
        InitSimplelink(ROLE_STA);
     
        UART_PRINT("wakeup\r\n");
        for (i = 0; i < 100; i++) LOG_GetEpoch();
        powerShutdown(3000);
    }

    and the log shows during the current active window wrong results:

    [SYS] SlDateTime_t: 2017/12/7 16:40:57
    [SYS] struct tm: 117/11/7 16:40:57
    [SYS] time_t   : 1512664857
    [SYS] SlDateTime_t: 2022/3/10 3:23:5
    [SYS] struct tm: 122/2/10 3:23:5
    [SYS] time_t   : 1646882585
    [SYS] SlDateTime_t: 2017/12/7 16:40:57
    [SYS] struct tm: 117/11/7 16:40:57
    [SYS] time_t   : 1512664857
    
    [SYS] SlDateTime_t: 2017/12/7 16:41:13
    [SYS] struct tm: 117/11/7 16:41:13
    [SYS] time_t   : 1512664873
    [SYS] SlDateTime_t: 2022/3/10 3:23:21
    [SYS] struct tm: 122/2/10 3:23:21
    [SYS] time_t   : 1646882601
    [SYS] SlDateTime_t: 2017/12/7 16:41:13
    [SYS] struct tm: 117/11/7 16:41:13
    [SYS] time_t   : 1512664873
    
    [SYS] SlDateTime_t: 2017/12/7 16:41:17
    [SYS] struct tm: 117/11/7 16:41:17
    [SYS] time_t   : 1512664877
    [SYS] SlDateTime_t: 2022/3/10 3:23:25
    [SYS] struct tm: 122/2/10 3:23:25
    [SYS] time_t   : 1646882605
    [SYS] SlDateTime_t: 2017/12/7 16:41:17
    [SYS] struct tm: 117/11/7 16:41:17
    [SYS] time_t   : 1512664877
    

    I got 250 wrong values in less than 60.000 readings.
    The differences seem to be equal to 134.217.728, whatever it might mean.

  • Another bit of information. 134.217.728 is 0x8000000. It happens ALL wrong readings have that bit set.
    Few minutes ago I discovered the opposite: on a sl_DeviceSet writing (I was setting the RTC) it set the value 134.217.728 seconds BEFORE the actual datetime I set:

    SlDateTime_t dateTime = {0};
    dateTime.tm_year = year;
    dateTime.tm_mon = month;
    dateTime.tm_day = day;
    dateTime.tm_hour = hour;
    dateTime.tm_min = min;
    dateTime.tm_sec = sec;

    ret = sl_DeviceSet(SL_DEVICE_GENERAL, SL_DEVICE_GENERAL_DATE_TIME, sizeof(SlDateTime_t), (const unsigned char *) &dateTime);
    ASSERT_ON_ERROR(ret);

    The wrong readings have a short duration. Reading again (with the same function) the RTC after 10 ms leads to the correct value. I'm not using any RTOS, and as reported above I'm using an extremely simple test program.