I'm running the Nordic/Thread SDK 3.2 with an NRF52840 (Rigado BMD-340) on SES 4.42.
I've got a project using BLE + Thread and I'm having problems implementing a hardware timer interrupt. I've cut this down to bare bones to try to understand what I'm doing wrong here, and I'm trying to generate an interrupt every 750mS via Timer2 Compare_Event 0.
I'm modifying the ble_thread_dyn_template example project with the following:
- Add /modules/nrfx/drivers/src/nrfx_timer.c to the nRF_Drivers folder
- Include nrf_drv_timer.h in main.c.
-Modify the sdk_config.h to enable Timer2
If I paste this code into the Timer Peripheral example and call 'hw_timers_init();' from the main loop then it works as expected, I get an interrupt every 750mS. If I put this in the ble_thread_dyn_template example then I am unable to clear the Timer2 Event flag and the code just lives in the ISR.
const nrf_drv_timer_t HW_DELAYTIME = NRF_DRV_TIMER_INSTANCE(2); //softdevice uses Timer0, OpenThread uses Timer1 //this is the handler for hardware timer 1 which will be used to control the delay between turning on the IR_LED and then checking the void hw_timer_event_handler(nrf_timer_event_t event_type, void* p_context){ ret_code_t err_code; volatile uint32_t dummy; switch (event_type) { case NRF_TIMER_EVENT_COMPARE0: // NRF_LOG_INFO("At hardware timer handler"); NRF_TIMER2->EVENTS_COMPARE[0] = 0; dummy = NRF_TIMER2->EVENTS_COMPARE[0]; dummy; nrf_gpio_pin_toggle(31); break; } } //function to initialize hardware timers. static void hw_timers_init(void){ nrf_gpio_cfg_output(31); //IO config shouldn't go in timers init, but pasting here for simple portablility with Timer example ret_code_t err_code; uint32_t time_ms = 750; //Time(in miliseconds) between timer start and rollover. uint32_t time_ticks; nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; err_code = nrf_drv_timer_init(&HW_DELAYTIME, &timer_cfg, hw_timer_event_handler); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_ms_to_ticks(&HW_DELAYTIME, time_ms); nrf_drv_timer_extended_compare( &HW_DELAYTIME, NRF_TIMER_CC_CHANNEL0, time_ticks,NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrf_drv_timer_enable(&HW_DELAYTIME); }
If anybody has any thoughts on what I'm doing wrong here I would really appreciate it