Hi
I want a 1K Hz square waveform to drive a peripheral device, but I can not get a continuously square waveform on GPIO 19, pls have a look at the picture I attached, the following is the timer initialization and interrupt routine, pls help check why this happened, thanks.
////////////////////////////////////////////////////////////////////////////Timer2 init static void timer2_init (void) { NRF_TIMER2->TASKS_STOP = 1; // Create an Event-Task shortcut to clear TIMER0 on COMPARE[0] event NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit; NRF_TIMER2->PRESCALER = timer2_prescaler_set; // timer2_prescaler_set = 4
NRF_TIMER2->TASKS_CLEAR = 1; // clear the task first to be usable for later
NRF_TIMER2->CC[0] = timer2_interval; //timer2_interval = 500
NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
/* Create an Event-Task shortcut to clear TIMER1 on COMPARE[0] event. */
// NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
sd_nvic_SetPriority (TIMER2_IRQn, APP_IRQ_PRIORITY_LOW); // Setzt die Prioroität auf HIGH
sd_nvic_EnableIRQ (TIMER2_IRQn); // Aktiviert den Interrupt
NRF_TIMER2->TASKS_START = 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////// void TIMER2_IRQHandler(void) { uint16_t i;
if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0) && \
((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE0_Msk) != 0))
{
NRF_TIMER2->EVENTS_COMPARE[0] = 0;
NRF_TIMER2->CC[0] += timer2_interval;
nrf_gpio_pin_toggle(19);
}
}