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

NRF_TIMER2 error?

I want to create a 1MHz timer using TIMER2.

I try to start the timer with the following settings, but the device probably hangs.

I also use app_timer, is it a problem to use it at the same time?

What I want to do is read the counter value of the 1MHz timer when the button is interrupted.

    NRF_TIMER1->TASKS_STOP  = 1;
    NRF_TIMER2->MODE        = TIMER_MODE_MODE_Timer;
    NRF_TIMER2->BITMODE     = TIMER_BITMODE_BITMODE_16Bit;
    NRF_TIMER2->PRESCALER   = 6;
    NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos;//CC[1]  
    NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE2_Enabled << TIMER_INTENSET_COMPARE2_Pos;//CC[1]
    NVIC_EnableIRQ(TIMER2_IRQn);
    NRF_TIMER2->TASKS_START = 1;

  • Hi,

    hrms said:
    TIMER is now working, but interrupts are not working properly.
    When the interrupt timing specified in CC[] is reached, the IRQHadler is not processed.
    Are there any possible causes?

    As before I do not know enough about your code to say anything with certainty. Please share your code. Without that, I can make some guesses. I am surprised that you need to enable TIMER_ENABLED in sdk_config.h as you have shared code that use the TIMER peripheral directly, not via the driver. When the driver is used, it will implement the interrupt routine (nrfx_timer_x_irq_handler). Is that the one that is being used and not your own? (you would get a compiler warning if multiple are used, though).

    hrms said:
    I also have one more question.
    I heard information that 32Bit cannot be specified for TIMER2, but I can get the timer value with BITMODE_332Bit and it seems to work.
    Does this cause any problems?

    All TIMER instances on all nRF52 variants are 32 bit. That was not the case for nRF51 though, so perhaps that is where you have this information from.

Related