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

RTC1 interrupt does't trigger, and what's event counter?

I'm try to use RTC1 to generate overflow interrupt, but it doesn't trigger interrupt.

void RTC1_IRQHandler(void)
{
  // do something
}

main()
{
  NRF_RTC1->TASKS_STOP = 1;
  NRF_RTC1->INTENSET = 0x2; // enable OVRFLW interrupt
//  NVIC_SetVector(RTC1_IRQn, (uint32_t) &RTC1_IRQHandler); // needed?
  NVIC_EnableIRQ(RTC1_IRQn );
  NRF_RTC1->TASKS_START = 1;
  while(1)
}

In my understanding, the vector for RTC1_IRQn() is already assigned in start-up code, so I skipped NVIC_SetVector(), however, the interrupt doesn't trigger even if setting NVIC_SetVector().

By watching the value of RTC1->COUNTER, it increments automatically, and OVRFLW event occurs by enabling overflow event by setting "NRF_RTC1->EVTENSET = 0x2;"

I also confusing the function of event counter. Does the event counter increments at every event? For example, in the following code, the event counter, NRF_RTC1->EVENTS_TICK, becomes 1 after the first tick, but it keeps 1. Doesn't event counter increase more than 1? (In other words, can I check it simply for checking event occurred or not?)

main()
{
  NRF_RTC1->TASKS_STOP = 1;
  NRF_RTC1->EVTENSET = 0x1; // enable Tick event
  NRF_RTC1->TASKS_START = 1;
  while(1)
}
  • FormerMember
    0 FormerMember in reply to akita

    Before starting the LFCLK, it has to be configured, by setting the clock source and the CTIV. CTIV should only be necessary if the internal RC oscillator is being used. To start the LFCLK you should do the following:

    NRF_CLOCK->LFCLKSRC = clock source
    NRF_CLOCK->CTIV     = ...
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while(EVENTS_LFCLKSTARTED == 0)
    {
    }
    // continue
    

    Could you check if making sure that the LFCLK is running change anything?

    I wouldn't think that the RTC would increment if the LFCLK is not running..but if it is incrementing while the clock is not running, I would think it is quite unreliable.

  • I've checked LFCLK status for details (in main(), after mbed's startup and initialization codes), by reading related register as follows:

    • NRF_CLOCK->LFCLKRUN 0x1 : task triggered
    • NRF_CLOCK->LFCLKSTAT 0x10000 : LFCLK running, src=RC osc
    • NRF_CLOCK->EVENTS_LFCLKSTARTED 0x0 : LFCLK not started?
    • NRF_CLOCK->LFCLKSRC 0x0 : src=RC osc
    • NRF_CLOCK->LFCLKSRCCOPY 0x0 : src=RC osc

    LFCLKSTAT=0x10000 means that LFCLK is running with RC oscillarator, however, I wonder that EVENTS_LFCLKSTARTED is 0x0...?

  • FormerMember
    0 FormerMember in reply to akita

    For the EVENTS_LFCLKSTARTED to trigger, the NRF_CLOCK->INTENSET register has to be set.

Related