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

rtc nrf51 SDK example matches COMPARE0 only once

In order to learn how to use the RTC0 to handle an event every second, I am debugging the rtc SDK example.

Expectation: The rtc example sets the time to check the counter time at 3 seconds. I expect every 3 seconds. the int_type in rtc_handler() will equal NRF_DRV_RTC_INT_COMPARE0.

What I am seeing: the int_type in rtc_handler() equals NRF_DRV_RTC_INT_COMPARE0 after the first three seconds. Then int_type equals only NRF_DRV_RTC_INT_TICK.

Question: is my assumption correct the COMPARE0 should keep repeating such that there is a match every 3 seconds (in this example)

Question: If not, what is the example missing to do so?

thank you.

Parents
  • sadly, I already had :-).... my question then is one of usage. Please forgive this basic question however, I do not know the answer. What I cannot get working is calling the interrupt handler for COMPARE0 every 3 seconds. I.e.: it only gets called once. On further debugging, I thought the following would work. Why does it not work? Thank you.

    static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
    {
        if (int_type == NRF_DRV_RTC_INT_COMPARE0)
        {
            nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
            //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
            uint32_t err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME*RTC0_CONFIG_FREQUENCY,true);
            APP_ERROR_CHECK(err_code);
            //Power on RTC instance
            nrf_drv_rtc_disable(&rtc);
            nrf_drv_rtc_enable(&rtc);
        }
        else if (int_type == NRF_DRV_RTC_INT_TICK)
        {
            nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
        }
    }
    
Reply
  • sadly, I already had :-).... my question then is one of usage. Please forgive this basic question however, I do not know the answer. What I cannot get working is calling the interrupt handler for COMPARE0 every 3 seconds. I.e.: it only gets called once. On further debugging, I thought the following would work. Why does it not work? Thank you.

    static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
    {
        if (int_type == NRF_DRV_RTC_INT_COMPARE0)
        {
            nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
            //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
            uint32_t err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME*RTC0_CONFIG_FREQUENCY,true);
            APP_ERROR_CHECK(err_code);
            //Power on RTC instance
            nrf_drv_rtc_disable(&rtc);
            nrf_drv_rtc_enable(&rtc);
        }
        else if (int_type == NRF_DRV_RTC_INT_TICK)
        {
            nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
        }
    }
    
Children
No Data
Related