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.

Problem with time() function from time.h library

Hello,

Met interesting problem during debugging software. I'm trying to use hibernate module also as RTC.

I use Tiva launchpad TM4C123G and IAR

struct tm *current_time;
time_t rawtime;

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
HibernateRTCSet(0);
HibernateRTCEnable();
current_time->tm_hour = 20;
current_time->tm_min  = 10;
current_time->tm_sec  = 0;

LED_ON();                              // indicate
time(&rawtime);                     // here's controller becomes frozen in free run mode
LED_OFF();                            // indicate successful time() execution
current_time = localtime(&rawtime);
UARTprintf("\n Seconds %i", current_time->tm_sec);

This code works well if I use it in debug mode. But in normal work microcontroller becomes frozen with LED turned ON.

Any suggestions are appreciated

  • Hello Rasul,

    The API Call to Enable the Hibernate 32K clock is not there in the code. This has to be done after the SysCtlPeripheralEnable API call

    HibernateEnableExpClk

    Regards

    Amit

  • Dear Amit. Thank you. Your suggestion is correct but it don't resolve the problem. It was firtst step to do that)

    This code is correct now:

    struct tm *current_time;
    time_t rawtime;
    
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); 
    ROM_HibernateEnableExpClk(SysCtlClockGet());
    ROM_SysCtlDelay(10);
    ROM_HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);
    HibernateRTCSet(0);
    HibernateRTCEnable();
    
    rawtime = HibernateRTCGet();
    LEDB0_ON();
    //rawtime = time(NULL);           <- commented
    current_time = localtime(&rawtime);
    LEDB0_OFF();
    UARTprintf("\n Seconds %i", current_time->tm_sec);

  • Hello Rasul,

    I think the following section of code would have done the required intent.

    rawtime = HibernateRTCGet();
    current_time = localtime(&rawtime);

    Regards

    Amit