RTC with PPI, interrupts stops after two events

Hi,

I'm trying to use RTC to generate interrupts at every second. The rtc event handler is below:

void rtc_event_handler(nrfx_rtc_int_type_t int_type)
{
    static int32_t cnt = 0;
    LOG_DBG("RTC Interrupt: %d, %d", int_type, cnt++);
    //nrfx_rtc_counter_clear(&rtc);
    //nrfx_rtc_cc_set(&rtc, 0, 32768, true);
}

In the RTC examples, nrfx_rtc_counter_clear is used to reset the RTC count; therefore, the interrupt event continues. Since my intention is to use this to trigger an ADC at 1 Hz, I used a PPI channel to clear the counter. However, there are only two interrupts after power-up, and then no more interrupts occur unless I uncomment either nrfx_rtc_counter_clear or nrfx_rtc_cc_set. The RTC initialization is shown below

const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(2);
#define NRFX_RTC_MS_TO_TICKS(us,freq) (((us) * (freq)) / 1000U)
void init_rtc()
{
    nrfx_err_t err;
    nrfx_rtc_config_t rtc_cfg = NRFX_RTC_DEFAULT_CONFIG;
    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(rtc2)),
                DT_IRQ(DT_NODELABEL(rtc2), priority), 
                nrfx_isr, NRFX_RTC_IRQ_HANDLER(RTC_INSTANCE), 0);

    err = nrfx_rtc_init(&rtc, &rtc_cfg, rtc_event_handler);
    if (err != NRFX_SUCCESS) {
        LOG_ERR("Failed to initialize RTC-0, %d", err);
        return;
    }

    uint32_t rtc_ticks = NRFX_RTC_MS_TO_TICKS(SAMPLE_INTERVAL_MS, NRF_RTC_INPUT_FREQ);

    err = nrfx_rtc_cc_set(&rtc, 0, rtc_ticks, true);
    if (err != NRFX_SUCCESS) {
        LOG_ERR("Failed to set RTC comparator");
    }

    static uint8_t m_rtc_counter_clear;
    nrfx_ppi_channel_alloc(&m_rtc_counter_clear);

    /* channel, eep, tep task endpoint address*/
    nrfx_ppi_channel_assign(m_rtc_counter_clear, 
        nrfx_rtc_event_address_get(&rtc, NRF_RTC_EVENT_COMPARE_0),
            nrfx_rtc_task_address_get(&rtc, NRF_RTC_TASK_CLEAR));


    nrfx_ppi_channel_enable(m_rtc_counter_clear);

    nrfx_rtc_enable(&rtc);
}

And the output is

```

*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
I: Starting Application
D: RTC Interrupt: 0, 0
D: RTC Interrupt: 0, 1

```

Parents Reply Children
No Data
Related