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

How to set the tick of RTC for one second?

How to set the tick of RTC to, for example, one second. And then calculate the current time base on the RTC counter.?

i need to calculate time from the RTC so that i can See the time when the Peripheral is connected to Central.

i'm using peripheral RTC SDK example.in that how can i set the tick for one second and how can i calculate the time?

  • Hi,

    What do you mean by calculate the time? If you are asking how to convert that to hours and minutes etc, I'm sure there you will find some code only that can do that. 

    If you need the exact time then you shouldn't use the RTC on the nRF52 though. It is relatively inaccurate, and using the interrupts is not completely safe. Then it is better to use a dedicated Real Time Clock IC. 

    This is a quite common topic here on devzone: https://devzone.nordicsemi.com/search?q=keep%20time%20rtc#serpq=keep%20time%20rtc

  • #include "app_timer.h"
    
    #include "nrf_delay.h"
    
    #include "nordic_common.h"
    
    APP_TIMER_DEF(Sip_timer);                 // Creates timer id for our program.
    
    
    
    /**@brief Function for the Timer .
     *
     * @details Blink 1 led
     */
    
    void timer_timeout_handler(void * p_context)
    {
      bsp_board_led_on(0);
      nrf_delay_ms(200);   //
      bsp_board_led_off(0);
    }
    
    
    
    /**@brief Function for the Timer initialization.
     *
     * @details Initializes the timer module. This creates application timers.
     */
    static void timers_init(void)
    {
        // Initialize timer module.
        ret_code_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
    
        // Create timers.
    
        /* YOUR_JOB: Create any timers to be used by the application.
                     Below is an example of how to create a timer.
                     For every new timer needed, increase the value of the macro APP_TIMER_MAX_TIMERS by
                     one.*/
     
           err_code = app_timer_create(&Sip_timer, APP_TIMER_MODE_REPEATED, timer_timeout_handler);
           APP_ERROR_CHECK(err_code);
    }
    
    
    
    
    /**@brief Function for starting timers.
     */
    static void application_timers_start(void)
    {
        /* YOUR_JOB: Start your timers. below is an example of how to start a timer.*/
           ret_code_t err_code;
           err_code = app_timer_start(Sip_timer, APP_TIMER_TICKS(1000), NULL); //1000 ms= 1 seg
           APP_ERROR_CHECK(err_code);
     
        
    }
    
    
    
    
    int main(void)
    {
    
    application_timers_start();
    
    }
    

Related