This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTC2 doesn't work on nRF52840 DK : RTC example.

Hello,

I am trying to get the RTC2 working in order to maintain time for my application. I intend to use the BLE DFU feature in my application and so I am using the softdevice (uses RTC0). I am aware that the application timer which uses (RTC1). That is the reason I chose to use RTC2 after going through various forum posts advising this. 

Now the problem that I am facing is I am successfully able to merge my RTC code with my BLE application code. But the RTC2 doesn't seem to be working. If I comment out the BLE code and change my RTC to RTC0 it works fine.

To make sure that RTC2 works I modified the basic RTC example that Nordic provides. The original example used RTC0, so I modified it to make it work for RTC2. And that too doesn't work. I tried to get the RTC1 and that didn't work either.

For the RTC example I made following changes to get it to work.

In sdk_config.h =>

#define RTC2_ENABLED 1

In main.c

const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2); /**< Declaring an instance of nrf_drv_rtc for RTC0. */

/** @brief: Function for handling the RTC0 interrupts.
 * Triggered on TICK and COMPARE0 match.
 */
static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    if (int_type == NRF_DRV_RTC_INT_COMPARE2)
    {
        nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
        nrf_drv_rtc_counter_clear(&rtc);
        nrf_drv_rtc_int_enable(&rtc, NRF_RTC_INT_COMPARE2_MASK);
    }
    else if (int_type == NRF_DRV_RTC_INT_TICK)

    {
        nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
    }
}

  • I found what the issue was. The 'nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME * 8,true);' call had channel set to 0. (Second parameter passed is the compare channel)

    This is the reason it worked with RTC0 but didn't work with other RTCs.

Related