Hi,
I'm trying to use RTC to generate interrupts at every second. The rtc event handler is below:
Fullscreen
1
2
3
4
5
6
7
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
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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");
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
```