In my nRF52810 based circuit board I'm trying to use the RTC along with the RTC tick interrupt to toggle an IO pin every 6msec. In main.c I use WFE to enter low power mode between the RTC tick event interrupts. This seems to work fine with the output pin toggling every 6 msec as desired, but 25 seconds later, the output toggle period changes from 6 msec to about every 7 seconds. This event is very repeatable. If I comment out the WFE instruction, the problem goes away. Can you point me in the right direction? See the “code” below.
// Configure LFCLK void lfclk_config(void) { // Initialize the low frequency clock nrf_drv_clock_init(); // Request the clock to not generate events nrf_drv_clock_lfclk_request(NULL); } // RTC1 interrupt handler void rtc1_handler(nrfx_rtc_int_type_t int_type) { nrf_gpio_pin_toggle(output_pin); // toggle output } // Configure the RTC1 void rtc1_config(void) { nrfx_rtc_config_t rtc1_config = NRFX_RTC_DEFAULT_CONFIG; // Configure the RTC to tick every 6.25ms which results in an 80HZ output frequency rtc1_config.prescaler = 203; // tick = 32768 / (203 + 1) = 80Hz = 12.5msec (all approximate). // Initialize the rtc nrfx_rtc_init(&rtc1, &rtc1_config, rtc1_handler); // Enable a tick interrupt on each tick nrfx_rtc_tick_enable(&rtc1, true); // start the rtc nrfx_rtc_enable(&rtc1); } int main(void) { gpio_init(); // Initialize the gpio lfclk_config(); //low frequency low power clock configuration nrfx_clock_lfclk_start(); rtc1_config(); // rtc1 configuration while (true) { __WFE(); } }