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

nRF52810 Timer 2 not working

Hello All , 

I want to use timer 2 of nRF52810..my code is not giving any error but timer is also not going to IRQ handler...but if i made the same changes for timer 0 it working..

sharing my code...what should be the issue?..

Thanks in Advance....

void timer2_init(void)

{
NRF_TIMER2->TASKS_STOP = 1; // Stop timer
NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // taken from Nordic dev zone
NRF_TIMER2->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos);
NRF_TIMER2->PRESCALER = 60 ;
NRF_TIMER2->TASKS_CLEAR = 1; // Clear timer
NRF_TIMER2->CC[1] = 30999; //842//421 ;
NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos; // taken from Nordic dev zone
NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
NVIC_EnableIRQ(TIMER2_IRQn);
NRF_TIMER2->TASKS_START = 1; // Start TIMER STOP AS WE USE IT FOR SOFTWARE UART SO WE START IT WHEN REQUIRED
}

void nrfx_timer_2_irq_handler(void)
{
if (NRF_TIMER2->EVENTS_COMPARE[0] &&
NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE1_Msk)
{

// clear compare register event
NRF_TIMER2->EVENTS_COMPARE[0] = 0;

// toggle pin
nrf_gpio_pin_toggle(PIN_OUT) ;
}

}

Parents
  • can you please give me reference code...i just want to use timer 2 which goes to IRQ every 1 sec

  • Did you even try the suggestions I gave you?

    I tested the following code on a nRF52832/nRF52 DK, and it works as expected, toggling LED every 1 second:

    void timer2_init(void)
    
    {
        NRF_TIMER2->TASKS_STOP = 1; // Stop timer
        NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // taken from Nordic dev zone
        NRF_TIMER2->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos);
        NRF_TIMER2->PRESCALER = 9 ;
        NRF_TIMER2->TASKS_CLEAR = 1; // Clear timer
        NRF_TIMER2->CC[1] = 31250; //842//421 ;
        NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos; // taken from Nordic dev zone
        NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
        NVIC_EnableIRQ(TIMER2_IRQn);
        NRF_TIMER2->TASKS_START = 1; // Start TIMER STOP AS WE USE IT FOR SOFTWARE UART SO WE START IT WHEN REQUIRED
    }
    
    void nrfx_timer_2_irq_handler(void)
    {
        if (NRF_TIMER2->EVENTS_COMPARE[1] &&
        NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE1_Msk)
        {
    
        // clear compare register event
        NRF_TIMER2->EVENTS_COMPARE[1] = 0;
    
        // toggle pin
        nrf_gpio_pin_toggle(LED_1) ;
        }
    
    }
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        nrf_gpio_cfg_output(LED_1);
        nrf_gpio_pin_set(LED_1);
    
        timer2_init();
    
        while (1)
        {
            __WFI();
        }
    }

Reply
  • Did you even try the suggestions I gave you?

    I tested the following code on a nRF52832/nRF52 DK, and it works as expected, toggling LED every 1 second:

    void timer2_init(void)
    
    {
        NRF_TIMER2->TASKS_STOP = 1; // Stop timer
        NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // taken from Nordic dev zone
        NRF_TIMER2->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos);
        NRF_TIMER2->PRESCALER = 9 ;
        NRF_TIMER2->TASKS_CLEAR = 1; // Clear timer
        NRF_TIMER2->CC[1] = 31250; //842//421 ;
        NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE1_Enabled << TIMER_INTENSET_COMPARE1_Pos; // taken from Nordic dev zone
        NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
        NVIC_EnableIRQ(TIMER2_IRQn);
        NRF_TIMER2->TASKS_START = 1; // Start TIMER STOP AS WE USE IT FOR SOFTWARE UART SO WE START IT WHEN REQUIRED
    }
    
    void nrfx_timer_2_irq_handler(void)
    {
        if (NRF_TIMER2->EVENTS_COMPARE[1] &&
        NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE1_Msk)
        {
    
        // clear compare register event
        NRF_TIMER2->EVENTS_COMPARE[1] = 0;
    
        // toggle pin
        nrf_gpio_pin_toggle(LED_1) ;
        }
    
    }
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        nrf_gpio_cfg_output(LED_1);
        nrf_gpio_pin_set(LED_1);
    
        timer2_init();
    
        while (1)
        {
            __WFI();
        }
    }

Children
No Data
Related