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

nrf52840 Calendar Timestamp issue

We have successfully implemented & tested the working of SYSTEM ON SLEEP MODE feature in our nrf52840 devices.

Please reply to below queries for a similar issue:

  1. Will TIMESTAMP from internal RTC work in SYSTEM ON SLEEP MODE. We are implementing get_time() as below: https://github.com/NordicPlayground/nrf5-calendar-example

struct tm *nrf_cal_get_time_calibrated(void)
{
time_t uncalibrated_time, calibrated_time;
if(m_calibrate_factor != 0.0f)
{
uncalibrated_time = m_time + CAL_RTC->COUNTER / 8;
calibrated_time = m_last_calibrate_time + (time_t)((float)(uncalibrated_time - m_last_calibrate_time) * m_calibrate_factor + 0.5f);
m_tm_return_time = *localtime(&calibrated_time);
return &m_tm_return_time;
}
else return nrf_cal_get_time();
}

ABOVE IS NOT WORKING NOT ABLE TO SET TIMESTAMP TO CURRENT DATE/TIME OR MAINTAIN TIMESTAMP

 

  1.   How to properly implement & maintain TIMESTAMP for device with SYSTEM ON SLEEP MODE? Any code snippet or calendar drivers that will work with internal RTC only as we don't have external RTC provision due to device size constrains?

 

Please check & reply with your valuable feedbacks/suggestions!

 

--

Regards


Vishal Aditya
Embedded Software Engineer

Parents
  • Hello Vishal,

     

    ABOVE IS NOT WORKING NOT ABLE TO SET TIMESTAMP TO CURRENT DATE/TIME OR MAINTAIN TIMESTAMP

     Can you clarify the behavior? What do you mean by "NOT WORKING"? Does the error handler trigger? Are you not able to connect? What is happening?

     

      How to properly implement & maintain TIMESTAMP for device with SYSTEM ON SLEEP MODE? Any code snippet or calendar drivers that will work with internal RTC only as we don't have external RTC provision due to device size constrains?

     Well... there is that project that you link to. It is not something that is officially provided by Nordic, but it was made for a project at one point, and we published it in case someone else could benefit from it. There is no library in the SDK made for this.

    I suspect that you use a different SDK version than the one used in the NordicPlayground repository, is that correct? If so, you probably need to adapt some of the functions to the correct SDK version. 

    Why don't you describe how it behaves, and what SDK version you are trying to use, and we can look into it together.

    Best regards,

    Edvin

  • Hi Edvin,

    We are using SDK 15.2: nRF5_SDK_15.2.0_9412b96\examples\ble_peripheral

    Issue with https://github.com/NordicPlayground/nrf5-calendar-example is below:

    nrf_cal_set_time() function is not working getting stuck/hanged incountered after debugging on nrf52840 DK in Keil 5 with a break point.


    Please confirm if TIMESTAMP from internal RTC will work in SYSTEM ON SLEEP MODE?

  • Vishal Aditya said:
    nrf_cal_set_time() function is not working getting stuck/hanged incountered after debugging on nrf52840 DK in Keil 5 with a break point.

     So it stops because you have set a breakpoint? Isn't that the intention of breakpoints?

    Or do you mean that you aren't able to input the time correctly? Maybe you are stuck on the "Enter year:" command?

    Note that the UART is looking for a CR = 0x0D (Carriage Return), and not the Linefeed. For your reference: Ascii table.

     

    Vishal Aditya said:
    Please confirm if TIMESTAMP from internal RTC will work in SYSTEM ON SLEEP MODE?

     The RTC doesn't have a TIMESTAMP directly. But if your question is whether the RTC will run in SYSTEM ON mode, then the answer is yes. However, this example doesn't use system on mode. Have you merged this example into a BLE example? Did you test it standalone first?

    There are many things that can go wrong that I can think of when I try to imagine what you may or may not be doing, but it is difficult without knowing much. 

    Did you do any changes to the project? It works unmodified in the SDK15.2.0. Did you try to copy it into a BLE project? It may be that the softdevice is not a huge fan of app_uart_get (but I think it will be alright). The softdevice is not working after a break on a breakpoint. At that point, you need to reset your device, because the softdevice has missed too many time critical events (if you use the softdevice).

    Best regards,

    Edvin

  • Thanks for your detailed answers!

    I am debugging properly with break-points at each line.

    I am trying to set timestamp using function below from nrf_calendar example:

    void nrf_cal_set_time(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t minute, uint32_t second)
    {
        static time_t uncal_difftime, difftime, newtime;
        time_struct.tm_year = year - 1900;
        time_struct.tm_mon = month;
        time_struct.tm_mday = day;
        time_struct.tm_hour = hour;
        time_struct.tm_min = minute;
        time_struct.tm_sec = second;   
        newtime = mktime(&time_struct);
        CAL_RTC->TASKS_CLEAR = 1;  
        
        // Calculate the calibration offset 
        if(m_last_calibrate_time != 0)
        {
            difftime = newtime - m_last_calibrate_time;
            uncal_difftime = m_time - m_last_calibrate_time;
            m_calibrate_factor = (float)difftime / (float)uncal_difftime;
        }
        
        // Assign the new time to the local time variables
        m_time = m_last_calibrate_time = newtime;
    }    

    Function Call below:

    uint32_t g_year, g_month, g_day, g_hour, g_minute, g_second;
    
    g_year = 2018;
    g_month = 10;
    g_day = 15;
    g_hour = 5;
    g_minute = 1;
    g_second = 29;
    nrf_cal_set_time(g_year, g_month, g_day, g_hour, g_minute, g_second);

    Please let me know how I can further debug into issue for setting time as I am able to get time with this function: nrf_cal_get_time_calibrated()

    Result: 01/01/70 - 00:00:00

    Also, in int main(void){}

    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    nrf_cal_init();
    nrf_cal_set_callback(calendar_updated, 4);

    MCU stucks here.


    We have multiple peripherals & final ble_peripheral code which is all working for our devices, we are adding extra features to the same. 

    Yes merged with ble_peripheral

    Yes tested standalone in peripheral as well not working

    There are many things that can go wrong that I can think of when I try to imagine what you may or may not be doing, but it is difficult without knowing much. 

    Let me know all possible queries to resolve this issue I will answer all...

    I am not setting time from app_uart itself, 1st priority trying to set timestamp manually & maintain it for all reading cycles in SYSTEM ON SLEEP MODE. Further, we will develop our custom Android App & get AUTOSYNC of TIMESTAMP.

    As, such I am not falling or encountering any softdevice issue while debugging with Keil5, so I am not getting troubles with softdevice thing you mentioned above.

    Regards

    Vishal Aditya
    Embedded Software Engineer

  • Vishal Aditya said:
    Yes tested standalone in peripheral as well not working

     Maybe you should try that before mixing the softdevice into the project, so that you understand how it works. 

     

    Vishal Aditya said:
    I am debugging properly with break-points at each line.

     You can NOT do this with the softdevice. sorry. I can't stress this enough.

    Try with the project from the github repository that you linked to first. See that you get the calendar up and running first.

    Make sure that you end all your UART inputs with CR (Carriage return). 

    Do you mean that the MCU is getting stuck on the line: nrf_cal_set_callback(calendar_updated, 4);?

    That is not possible. Try to enter this function, and set breakpoints inside it. Where is it stuck?

Reply
  • Vishal Aditya said:
    Yes tested standalone in peripheral as well not working

     Maybe you should try that before mixing the softdevice into the project, so that you understand how it works. 

     

    Vishal Aditya said:
    I am debugging properly with break-points at each line.

     You can NOT do this with the softdevice. sorry. I can't stress this enough.

    Try with the project from the github repository that you linked to first. See that you get the calendar up and running first.

    Make sure that you end all your UART inputs with CR (Carriage return). 

    Do you mean that the MCU is getting stuck on the line: nrf_cal_set_callback(calendar_updated, 4);?

    That is not possible. Try to enter this function, and set breakpoints inside it. Where is it stuck?

Children
No Data
Related