This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to generate unix epoch time stamp using Nrf52840 ?

I have been working with nrf52 to produce unix time stamp but it using the rtc is a tougher task. Hence, Please help in providing a header file that has a macro such as time_t which had the ability to give current time as time stamp. I tried using header files given for arduino and C. I am getting error such as time_t type name not found. I am trying to get the time stamp using a simple hack. Please, help in providing a valid header file to provide the time epoch. The link for the header file is given below

codeload.github.com/.../master

Parents
  • Hi,

    There is no code for this in the SDK, so you have to implement it yourself. That should not be a big issue, though.

    If you use the nRF5 SDK I suggest you use the app_timer, and specifically the app_timer2.c implementation. That has a 64 bit timer that is always incrementing if you set APP_TIMER_KEEPS_RTC_ACTIVE to 1 in sdk_config.h, and you can use that as a reference. For that you need to slightly modify app_timer2.c, making the internal get_now() function not static. That way you can call that from your code and get a always increasing timer. To translate that to Unix epoch time you just need to divide the counter value based on the configured RTC prescaler so that you get it in seconds, and offset it by the time between January 1 1970 and the time your counter started (so you must sync this up externally somehow to get the initial time correct). Now you have the Unix time.

    You also mention time_t etc. As long as you have your Unix epoch time that would be generic and not related to nRF specific, so you should be ble to find some code you can adapt, but nordic does not provide it.

  • Hi Einar,

    I am a little confused about the process of 'syncing' that you have explained above. Could you provide some help on how to do the syncing part? 

    Thanks

    Ananye

Reply Children
Related