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

nRF52832 Timer interrupt not working

Hi,

I cannot get the interrupt on Timer1 to work. I have checked that the counter is matching the compare register by not enabling the interrupt. When I enable the interrupt the LED is never set.

I'm using the nRF52832 with SD132 and nRF5 SDK v11.0.0

Below is my code

void TIMER1_IRQHandler(void)
{
nrf_gpio_pin_set(RED_LED_PIN);
}

int main()
{

// Reset 16 MHz crystal
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_HFCLKSTARTED != 1)
{}
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_LFCLKSTARTED != 1)
{}
__enable_irq();

//Turn off LED
nrf_gpio_pin_clear(RED_LED_PIN);
//Config Pin
nrf_gpio_cfg(RED_LED_PIN, NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1,
NRF_GPIO_PIN_NOSENSE);

//Enable Timer

sd_nvic_DisableIRQ(TIMER1_IRQn);
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_STOP);
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_CLEAR);

nrf_timer_mode_set(NRF_TIMER1, TIMER_MODE_MODE_Timer);
nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_32);
nrf_timer_frequency_set(NRF_TIMER1, NRF_TIMER_FREQ_31250Hz);
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, 65534);
nrf_timer_int_enable(NRF_TIMER1, NRF_TIMER_INT_COMPARE0_MASK);

nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START);

sd_nvic_SetPriority(TIMER1_IRQn, 7);
sd_nvic_EnableIRQ(TIMER1_IRQn);

//Toggle LED to show alive

for(int i=0;i<2;) {
nrf_gpio_pin_toggle(RED_LED_PIN);
nrf_delay_ms(100);
i++;
}

while(1)
{
if(NRF_TIMER1->EVENTS_COMPARE[0] == 1)
{
nrf_gpio_pin_set(RED_LED_PIN);
}


}
}

Related