This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RTC interrupt handler not working.

static void RTC1_IRQHandler(void){
  
  NRF_RTC1->TASKS_CLEAR = 1;
  SEGGER_RTT_printf(0,"INTERRUPT TRIGGERED.\n");
  if(NRF_RTC1->EVENTS_COMPARE[0]){
    NRF_RTC1->EVENTS_COMPARE[0] = 0;
    }
}

static void RTC1_INIT(uint32_t time_ticks){

  NRF_RTC1->PRESCALER = 4095;      //prescaler = 4096
  NRF_RTC1->EVTEN = (1<<16);
  NRF_RTC1->EVTENSET = (1 << 16);   //enable event routing for COMPARE[0] event
  NRF_RTC1->INTENSET = (1 << 16);   //enable interrupt for compare[0] event
  NRF_RTC1->CC[0] = time_ticks;

  NVIC_SetPriority(RTC1_IRQn, 7);
  NVIC_EnableIRQ(RTC1_IRQn);

  NRF_RTC1->TASKS_START = 1;
  SEGGER_RTT_printf(0,"RTC STARTED.\n");
}

I am trying to initialize the RTC and trigger an interrupt every 10 seconds, and I am unsure of why the code above is not working. I followed a similar method to initialize Timer1 along with an interrupt function, and that works fine. As an additional question, is the difference in power savings between RTC and TIMER (using PCLK1M) significant?

Thanks for the help.

Parents Reply
  • Hello, yes I did start the LFCLK, as follows:

    NRF_CLOCK->LFCLKSRC = 1;
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    SEGGER_RTT_printf(0,"CLOCK STARTED.\n");

    However, the timer still does not seem to be working. The RTC1 peripheral appears to initialize in debug mode, but when running on its own it looks like the program gets stuck at starting the LF clock ("CLOCK STARTED" does not print). I am using the BMD-350 eval board.

Children
No Data
Related