Hi,
I am new to NORDIC dev and I find its ppi is really useful but also difficult to understand.
Now my device may be connected the truck engine to count the engine speed(rpm) with a gpio. The engine generates a pulse on the GPIO and the device needs to count it.
I want to use the gpiote + ppi + timer capture mode to implement it. so i coded it like this
static void rpm_init(void)
{
nrf_ppi_channel_t ppi_channel;
uint32_t gpiote_in_evt_addr;
uint32_t capture_task_addr;
ret_code_t err_code;
nrf_drv_gpiote_in_config_t config = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
err_code = nrf_drv_gpiote_in_init(PIN_DIN3_RPM, &config, rpm_event_handler);
APP_ERROR_CHECK(err_code);
// Check TIMER2 configuration for details.
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&m_timer2, &timer_cfg, empty_timer_handler);
APP_ERROR_CHECK(err_code);
gpiote_in_evt_addr = nrfx_gpiote_in_event_addr_get(PIN_DIN3_RPM);
capture_task_addr = nrfx_timer_capture_task_address_get(&m_timer2, NRF_TIMER_CC_CHANNEL0);
err_code = nrf_drv_ppi_channel_alloc(&ppi_channel);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(ppi_channel, gpiote_in_evt_addr, capture_task_addr);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_enable(ppi_channel);
APP_ERROR_CHECK(err_code);
nrfx_gpiote_in_event_enable(PIN_DIN3_RPM, true);
app_timer_start(rpm_timer_id, APP_TIMER_TICKS(1000), NULL);
}
the app timer rpm_timer_id is used to read the CC[0] of TIMER2. How ever, it seems the CC[0] is always 0.
Is there any wrong with my code?
Thank you