Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC overflw handler

Hello ,
I am working on the development kit nrf52, i want to know how  i canget  the value of the RTC overflw and then how i can reset the RTC to zero.

thank you in advance
Best regards

Parents
  • You cannot get the overflow value but you can get an overflow event in EVENTS_OVERFLW register. For this you have to enable this event in RTC->EVTEN register.

    You then need to enable interrupt for this in the INTENSET and increment a static variable everytime you get the overflow event. After incrementing the variable, you clear the overflow event.

    for example in the RTC interrupt handler you can do something like this

        static uint8_t tick_overflow_count = 0;
        /* check for overflow in RTC counter */
        if(nrf_rtc_event_pending(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW))
        {
            nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW);
            tick_overflow_count++;
        }
        
        // then you get the full value
        uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
        full_value = ((tick_overflow_count << portNRF_RTC_BITWIDTH) + systick_counter);

Reply
  • You cannot get the overflow value but you can get an overflow event in EVENTS_OVERFLW register. For this you have to enable this event in RTC->EVTEN register.

    You then need to enable interrupt for this in the INTENSET and increment a static variable everytime you get the overflow event. After incrementing the variable, you clear the overflow event.

    for example in the RTC interrupt handler you can do something like this

        static uint8_t tick_overflow_count = 0;
        /* check for overflow in RTC counter */
        if(nrf_rtc_event_pending(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW))
        {
            nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW);
            tick_overflow_count++;
        }
        
        // then you get the full value
        uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
        full_value = ((tick_overflow_count << portNRF_RTC_BITWIDTH) + systick_counter);

Children
Related