Issue with rtc in nrf52840

Hi i am using nRF52840 with segger embedded studio.

SDK -> nrf5-sdk 17.1.0

I want to configure rtc2 so that

whenver i initialize it it should generate an interrupt after certain interval and wakeup the system.

B_LED_RED is blinking but B_LED_BLUE is not blinking.

// RTC instance for RTC2
const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(2);
nrfx_rtc_config_t rtc_cfg = NRFX_RTC_DEFAULT_CONFIG;

// RTC wake-up handler
void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
if (int_type == NRFX_RTC_INT_TICK)
{

nrf_gpio_pin_toggle(B_LED_RED);
}

else if(int_type == NRFX_RTC_INT_COMPARE0)
{
nrf_gpio_pin_toggle(B_LED_BLUE);

}
}

void rtc_init(void)
{
rtc_cfg.prescaler = 4095; //1 tick 32768/(4095+1) = 8 Hz= 125ms/tick

uint32_t err_code;

err_code = nrfx_rtc_init(&rtc, &rtc_cfg, rtc_handler);
APP_ERROR_CHECK(err_code);

nrfx_rtc_tick_enable(&rtc, true);

nrfx_rtc_cc_set(&rtc, 0, 8, true);

nrfx_rtc_enable(&rtc);


}



  • Hi Sumit,

    How do you expect B_LED_BLUE to blink ? 
    The CC counter is not re-occuring, it's only triggered when the counter goes from N-1 to N (where N is what set in the CC[] register)

    So you either have to change the CC counter to the future (next 8 seconds, take care of the wrap around) or you should reset the COUNTER if you want it to be triggered again. 

    By default the nrfx_rtc driver will disable and clear the CC counter, so you won't see the event occur when COUNTER is overflow : 



Related