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

Using RTC to get real time for nRF9160DK

Hi Dev team,

I had an issue regarding getting the real time using RTC. I tried to follow the below dev zone blog but the CAL_RTC does not work in my code.

As such, I am unable to use this to build my application. Does nR9160DK not support "CAL_RTC" like "NRF_CLOCK" .

Can you let me know how I could use the below code to build my app for nRF9160DK.

https://devzone.nordicsemi.com/f/nordic-q-a/51781/rtc-31st-date-problem-in-nrf52840

Also, a question regarding RTC and LFCLK. How can I view the real time value using RTC and LFCLK.

I can see in the debugger that they are running but I need to know the real time through it. Some help in explaining this would be appreciated :).

Regards,

Adeel.

  • Hi Tobjorn,

    Yes, I had tried this basic RTC example and it worked for me. I was working on the other example as it was more of what I wanted when working with an interrupt.

    https://github.com/andenore/NordicSnippets/blob/master/examples/rtc/main.c

    The code works and I was trying to generate an interrupt on a compare event and that does not happen.

    I want to generate a compare event every 10 secs and so I set my CC[0] value to 327680. I want to trigger an interrupt as soon as the compare event is achieved and the interrupt should join back to the original program after 10 secs.

    When I run the code and view it in debug mode, I see that the counter as well as the compare register CC[0] resets to zero after the compare is achieved and the interrupt is not triggered. I assume that the code has to execute the interrupt handler RTC0_IRQHandler() after the compare event is done and the CC[0] value should not be reset to 0 automatically after the compare event.

    I have used the same code above and just changed the CC[0] value to 327680.

    Can you help me in identifying the issue here. 

    Regards,

    Adeel.

  • Hi Adeel

    Would the k_timer approach I suggested in one of the other cases be an alternative?

    It shouldn't be necessary to use a dedicated RTC for timing, since you have Zephyr timers available (similar to the app_timer module in the nRF5 SDK, if you have any experience with that). 

    Best regards
    Torbjørn

  • Hi Tobjorn,

    Yes. It could be and I am able to use the k_timers for generating timer interrupts after a certain defined time interval. But I also wanted to generate interrupts through an interrupt handler function that caters to the interrupts instantly through a handler.

    I tried it in the example mentioned above to try and enable an interrupt through NVIC_EnableIRQ (RTC0_IRQn). As per my understanding , this enabling of the interrupt should transfer the program to its handler function : void RTC0_IRQHandler(void) wherein I have a certain task written inside the handler function.

    Is there another example with the interrupt handler functions wherein I could check its functionality. I am basically trying to work on high priority interrupts.   

    Regards,

    Adeel.

  • Hi Adeel

    The NVIC API is not supported in Zephyr. 

    To enable an interrupt you have to do the following (using the RTC1 interrupt as an example):

    IRQ_DIRECT_CONNECT(RTC1_IRQn, 0, RTC1_IRQHandler, 0);
    irq_enable(RTC1_IRQn);

    Best regards
    Torbjørn

  • Hi Tobjorn,

    Oh okay. I found some examples that used NVIC. Is it compatible for the nRF52 series ?

    Regards,

    Adeel.

Related