Hi engineers,
This is my timer init code. I place it before functions timers_init() and ble_stack_init().
#include "tim.h" #include "led.h" const nrf_drv_timer_t TIMER_SAMPLE = NRF_DRV_TIMER_INSTANCE(0); /** * @brief Handler for timer events. */ void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context) { switch (event_type) { case NRF_TIMER_EVENT_COMPARE0: led1_toggle(); break; default: //Do nothing. break; } } void tim_init(void) { uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events. uint32_t time_ticks; uint32_t err_code = NRF_SUCCESS; //Configure TIMER_SAMPLE for generating simple light effect - leds on board will invert his state one after the other. nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; timer_cfg.frequency = (nrf_timer_frequency_t)9; timer_cfg.mode = (nrf_timer_mode_t)0; timer_cfg.bit_width = (nrf_timer_bit_width_t)0; timer_cfg.interrupt_priority = 7; timer_cfg.p_context = NULL; err_code = nrf_drv_timer_init(&TIMER_SAMPLE, &timer_cfg, timer_led_event_handler); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_SAMPLE, time_ms); nrf_drv_timer_extended_compare( &TIMER_SAMPLE, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrf_drv_timer_enable(&TIMER_SAMPLE); }
app_init() includes led and timer init function.
/**@brief Application main function. */ int main(void) { bool erase_bonds; ringbuffer_init(); app_init();//include led and timer init code // Initialize. //uart_init(); //log_init(); //buttons_leds_init(&erase_bonds); //power_management_init(); timers_init(); ble_stack_init(); gap_params_init(); gatt_init(); services_init(); advertising_init(); conn_params_init(); // Start execution. //printf("\r\nUART started.\r\n"); //NRF_LOG_INFO("Debug logging for UART over RTT started."); advertising_start(); // Enter main loop. for (;;) { //idle_state_handle(); } }
Cheers,
Sean