For a precision timer application I have an external temperature compensated RTC (DS3231) which produces a highly stable 32 kHz signal connected to pin 5
When I associate a software handler with the pin, I can count the events just fine.
Now I want to use the TIMER2 via PPI, but somehow I must be missing something. This is the code ( I tried various permutations of the same principle taken from different examples)
(error checks removed for clarity)
static nrf_drv_timer_t timer = NRF_DRV_TIMER_INSTANCE(2);
//static uint32_t cap;
void timer_dummy_handler(nrf_timer_event_t event_type, void * p_context){}
/* ......... */
nrf_drv_gpiote_init();
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG(2);
timer_cfg.mode = NRF_TIMER_MODE_COUNTER;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_16;
nrf_drv_timer_init(&timer, &timer_cfg, timer_dummy_handler);
nrf_drv_gpiote_in_config_t i_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
i_config.pull = NRF_GPIO_PIN_PULLUP;
nrf_drv_gpiote_in_init(5, &i_config, NULL);
nrf_gpio_cfg_sense_input(5, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
nrf_drv_gpiote_in_event_enable(5, true);
nrf_drv_ppi_init();
nrf_ppi_channel_t ppi1;
nrf_drv_ppi_channel_alloc(&ppi1);
nrf_drv_ppi_channel_assign(ppi1, nrf_drv_gpiote_in_event_addr_get(5), nrf_drv_timer_task_address_get(&timer, NRF_TIMER_TASK_COUNT));
nrf_drv_ppi_channel_enable(ppi1);
nrf_drv_timer_enable(&timer);
But every time I perform:
NRF_TIMER2->TASKS_CAPTURE[0];
uint32_t cnt = NRF_TIMER2->CC[0];
cnt is 0.
What am I missing?
Any help appreciated