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

Two timers on RTC1

Hi, This is loosely related to the other question I asked a few weeks ago (devzone.nordicsemi.com/.../two-interrupt-events-on-timer0) but this time I want to have two timers on RTC1 generating interrupt events. I'm using the internal RC clock. I'm trying the following code:


void lfclk_config()
{
  NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
  NRF_CLOCK->TASKS_LFCLKSTART = 1;
  while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}
  NRF_RTC1->PRESCALER = 32; //1kHz frequency
  NRF_RTC1->CC[0] = 9 * 1000;
  NRF_RTC1->CC[1] = 2 * 1000;

  NRF_RTC1->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
  NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk;
  NRF_RTC1->EVTENSET = RTC_EVTENSET_COMPARE1_Msk;
  NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE1_Msk;
  NRF_RTC1->TASKS_START = 1;
  NVIC_EnableIRQ(RTC1_IRQn);
}

void RTC1_IRQHandler()
{
  if (NRF_RTC1->EVENTS_COMPARE[0] != 0)
  {
    NRF_RTC1->EVENTS_COMPARE[0] = 0;
  }
  if (NRF_RTC1->EVENTS_COMPARE[1] != 0)
  {
    NRF_RTC1->EVENTS_COMPARE[1] = 0;
  }
}

int main(void) {

  lfclk_config();
  while(1) {
  }
}

Here I want to setup two comparators, a 9sec and a 2sec one. Each should generate a periodic interrupt on their respective interval which is then handled by RTC1_IRQHandler. The behaviour I see is that it seems that both comparators fire on time once but afterwards there's no interrupt generated. My intention is to have periodic interrupts, not a single one.

What am I doing wrong?

Thanks! florin

Parents Reply Children
No Data
Related