Hi, devzone!
I'm trying to use a timer to periodically change the digital output but it seems that the handler function is not called.
The whole code is based on the ble_peripheral/ble_app_uart and I added all the other functions and timer into that example. Following is the part related to a timer.
const nrf_drv_timer_t TIMER_ADC = NRF_DRV_TIMER_INSTANCE(2);
const nrf_drv_timer_t TIMER_INJECTOR = NRF_DRV_TIMER_INSTANCE(1);
...
void timer_handler(nrf_timer_event_t event_type, void * p_context)
{
return;
}
void timer_handler_injector(nrf_timer_event_t event_type, void * p_context)
{
nrf_gpio_pin_toggle(pin_injector_0);
nrf_gpio_pin_toggle(pin_injector_1);
nrf_gpio_pin_toggle(pin_injector_2);
}
void saadc_sampling_event_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
//timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_16;
timer_cfg.frequency = NRF_TIMER_FREQ_16MHz;
err_code = nrf_drv_timer_init(&TIMER_ADC, &timer_cfg, timer_handler);
APP_ERROR_CHECK(err_code);
/* setup m_timer for compare event every us */
uint32_t ticks = nrf_drv_timer_us_to_ticks(&TIMER_ADC, 50);
nrf_drv_timer_extended_compare(&TIMER_ADC,
NRF_TIMER_CC_CHANNEL0,
ticks,
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
false);
nrf_drv_timer_enable(&TIMER_ADC);
uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&TIMER_ADC,
NRF_TIMER_CC_CHANNEL0);
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
timer_compare_event_addr,
saadc_sample_task_addr);
APP_ERROR_CHECK(err_code);
}
...
void run_injector(void)
{
ret_code_t err_code;
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
timer_cfg.frequency = NRF_TIMER_FREQ_16MHz;
err_code = nrf_drv_timer_init(&TIMER_INJECTOR, &timer_cfg, timer_handler_injector);
APP_ERROR_CHECK(err_code);
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&TIMER_INJECTOR, 1000);
nrf_drv_timer_extended_compare(&TIMER_INJECTOR,
NRF_TIMER_CC_CHANNEL1,
ticks,
NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK,
false);
nrf_drv_timer_enable(&TIMER_INJECTOR);
}
The TIMER_ADC is attached to the ppi and SAADC works without any problem, maybe because it does not use the handler. However, I need TIMER_INJECTOR to work with a handler.
When I manually checked nrf_gpio_pin_toggle() instead of putting it in the handler, it worked well so the GPIO pin assignment is not the problem.
I made a breakpoint in the handler function and found that it never called.
While searching similar cases in the forum, I found may the app_timer prohibits timer handler but even though I changed TIMER_INJECTOR as app_timer it still did not work.
I need some help...