I have the code below initializing TIMER1 and and IRQ every 1ms. I call app_sched_event_put within the timer and I get a Hardfault.
Any hints on what is going on ?
Thanks.
void high_res_timer_init(){
// Stop timers
NRF_TIMER1->TASKS_STOP = 1;
// Clear timers
NRF_TIMER1->TASKS_CLEAR = 1;
// Set the timer1 in Timer Mode, and timer 2 in counter mode
NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
// Prescaler 4 produces 1MHz for timer1 frequency
NRF_TIMER1->PRESCALER = 4;
// Ensure 16 bit mode on both timers
NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
// 1ms interrupt
NRF_TIMER1->CC[0] = 1000;
NRF_TIMER1->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);
NVIC_EnableIRQ(TIMER1_IRQn);
// Start timers
NRF_TIMER1->TASKS_START = 1;
}
void TIMER1_IRQHandler(void) {
if ((NRF_TIMER1->EVENTS_COMPARE[0] != 0) && ((NRF_TIMER1->INTENSET & TIMER_INTENSET_COMPARE0_Msk) !=0)) {
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
NRF_TIMER1->TASKS_CLEAR = 1;
nt_time++;
if (count++ > 20) {
app_sched_event_put(&nt_time, sizeof(nt_time), mag_scheduler_event_handler);
count = 0;
}
dpin_toggle();
}
}