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.

CCS/LAUNCHXL-CC1352R1: Read current UNIX timestamp

Part Number: LAUNCHXL-CC1352R1
Other Parts Discussed in Thread: CC3220S

Tool/software: Code Composer Studio

Hi,

I have CC1352R1 development kit and i'm using simplelink_cc13x2_26x2 SDK. i have been trying to read the current timestamp using time API

time(NULL)

and it didn't work.

I browsed online for and searched for similar posts, but none of them helped me to solve this issue.

I perused this example but unfortunately it didn't fit my SDK (my config file couldn't recognize the "scripting" tool).

How can i get the current timestamp ?

Best regards,

Dekel

  • Hi Dekel, 

    Which version of the SDK are you using and which project?

    Can you share the code and what you have tried to make it work?

    Thanks, 
    Elin

  • Hi Elin,

    My SDK's version is 3_30_00_03 (i'm aware that it's not the latest).

    This is one of the examples i tried to use (but i didn't find a version which matches my SDK):

    dev.ti.com/.../node

    and this is the code i used based on the above example:

    #include <ti/net/utils/clock_sync.h>
    
        struct tm netTime;
        status = ClockSync_get(&netTime);
        if((status == 0) || (status == CLOCKSYNC_ERROR_INTERVAL))
        {
            printf("Local time = %s\n\r",asctime(&netTime));
        }
        else
        {
            printf("Error = %d\n\r",status);
        }
    
        //.cfg file
        var SlNet = scripting.addModule("/ti/net/SlNet");
        var SlNet1 = SlNet.addInstance();
    

    Trying compiling this code, got the following error message:

    "scripting is not defined"

    Besides that i tried using also:

    
    
    struct xdc_runtime_Types_FreqHz freq;
    Timestamp_getFreq(&freq);
    
    uint32_t start_time = Timestamp_get32();
    uint32_t t0 = start_time / freq.lo;
    printf("t0 timestamp is %u\r\n", t0);

    which printed a weird results.

    Additionally, this is the time() implementation i used:

    time_t ATTRIBUTE time(time_t *tout)
    {
        UInt32 t;
    
        /* Seconds_get() returns number of seconds since Jan 1, 1970 00:00:00 GMT. */
        t = ti_sysbios_hal_Seconds_get();
    
    #if defined(__ti__)
        /*
         *  TI time() function returns seconds since 1900, so add the number
         *  of seconds from 1900 to 1970 (2208988800).
         */
        t += 2208988800;
    #endif
    
        if (tout) {
            *tout = t;
        }
    
        return (t);
    }

    which returned the time 2208988800 plus the time passed since the program started (and it's not the current UNIX timestamp).

    Dekel

  • Hi Dekel, 

    The example you linked to is for the CC3220S Launchpad but you specified the CC1352R1 in your question. Which device are you using?

    Thanks, 
    Elin

  • Hi, as i mentioned in the first post, i'm using CC1352R1 development kit.

    I also said (maybe i wasn't clear) that i tried to use this example. i simply thought this example fits my SDK simplelink_cc13x2_26x2 version 3_30_00_03.

  • Hi Dekel, 

    Thanks for sharing. The reason why I asked is that the link you shared is for the CC3220S Launchpad so I just wanted to make sure that we are on the same page. 

    Okay, so there is no space for you to load the examples from the SDK? I haven't experienced any issues with using any of the default projects in the SDK (but I haven't tried them all). Which examples have you tried and what kind of error are you seeing when trying to load the example? 

    Thanks, 
    Elin

  • The 1352 has no WiFi. There is no way to use the 'net to set the clock. You have to do that yourself.

  • So if i understand correctly, there is not way to get the current timestamp from the CC1352R1 chip ?

    In addition, the only way i can get the timestamp is to manually set it myself (in some way) on boot, and then i will be able to read the current timestamp ?

  • Not that I know of, I had to set mine myself. If it is really an issue, you can get a gps or WWV clock module and read the time over serial.

  • Ok, thank you for replaying !

  • I have tried few examples in the SDK but none of them worked for me.

    After talking with Keith, i understood there isn't a standard way to retrieve the timestamp (like using time(NULL) in desktop computer)

    and i have to receive it via GPS or WWV clock module.

    Thank you for replaying !