How do I set TIMER2 to interrupt every 1 ms?
Sounds like a very basic question, but I haven't succeed. For TIMER1 I can get it working, but for TIMER2 the highest frequecy I have achieved is about 100 Hz.
The code is as follows:
void init_timer2(void)
{
// Start 32 MHz crystal oscillator
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
// Wait for the external oscillator to start up
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
// Do nothing.
}
NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER2->PRESCALER = 4; // what should be here?
NVIC_EnableIRQ(TIMER2_IRQn);
NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
NRF_TIMER2->CC[0] = ???;
NRF_TIMER2->CC[1] = ???;
NRF_TIMER2->CC[2] = ???;
NRF_TIMER2->CC[3] = ???;
NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE2_Enabled
<< TIMER_INTENSET_COMPARE2_Pos;
sd_softdevice_forward_to_application();
NRF_TIMER2->TASKS_START = 1;
}
I don't know what should be put into the place of '???'s above. I guess there is a good documentation somewhere, so I would be happy to get a pointer there, too. Indeed, a working code would be best.
Edit: Format (please use preformatted text button when inserting code)