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)
}
Parents
  • Yes, I'm sure LFCLK has started in startup routine in mbed (I'm using mbed-compiler for programming). Does RTC1's counter increments even if LFCLK doesn't start? (In my situation ,I've confirmed that RTC1's counter increments at specified speed by prescaler.)

  • 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.

Reply
  • 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.

Children
No Data
Related