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

Soft Device and Timers - how do they work together?

Hi all, I'm using Timer2 while having the SD enabled, and I'm having some problems. I don't seem to be able to reliably set the periodicity of the timer. No matter what I load in the CC[] register, the interrupt always triggers at the same frequency. Here's what I'm doing:

In main(), to initialize I have: sd_clock_hfclk_request(); do { sd_clock_hfclk_is_running(&p_is_running); } while (p_is_running == 0);

NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer; // Set the timer in Timer Mode NRF_TIMER2->PRESCALER = 0; // Prescaler 0 produces 1 MHz timer freq => 1 tick = 1 us NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit; // 16-bit mode

// Enable interrupt
NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;

// Set up interrupt handler
sd_nvic_ClearPendingIRQ(TIMER2_IRQn);
sd_nvic_SetPriority(TIMER2_IRQn, APP_IRQ_PRIORITY_LOW);
sd_nvic_EnableIRQ(TIMER2_IRQn);

Then, when a button is pressed, I have: NRF_TIMER2->TASKS_CLEAR = 1; // Clear the task first to be usable for later NRF_TIMER2->CC[0] = delay; NRF_TIMER2->TASKS_START = 1; // Start clocks

In the interrupt handler, where code execution goes next, I have: if (((NRF_TIMER2->EVENTS_COMPARE[0] == 1) && (NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE0_Msk))) { NRF_TIMER2->EVENTS_COMPARE[0] = 0;

... my specific code here... }

And finally when I'm done I do:

NRF_TIMER2->EVENTS_COMPARE[0] = 0; NRF_TIMER2->TASKS_STOP = 1; // Stop clocks

Did anybody run into this problem with Timers and the soft device? Maybe I have to call another SD API function that I'm not aware of?

Can someone provide an example of the Timers and the SD working together?

Thank you!

Gil

Parents Reply Children
Related