I am emulating a nRF52810 on a nRF52832 DevKit on the SDK v15. I have TWI and ADC (3 channels) assigned and both of them work just fine individually. When I put them together in a single file and try to send them over BLE NUS, the system fails. All the modules are initialized and I have found that the function call nrfx_ppi_channel_enable in the saadc_sampling_event_init returns an NRFX_ERROR_INVALID_STATE. So the APP_ERROR_CHECK(err_code) resets the entire system. I have tried to comment out APP_ERROR_CHECK but still, the code fails. I have attached my saadc_sampling_event_init function below,
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; err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, timer_handler); APP_ERROR_CHECK(err_code); /* setup m_timer for compare event every 400ms */ uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 400); nrf_drv_timer_extended_compare( &m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false); nrf_drv_timer_enable(&m_timer); uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, 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 = nrfx_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_task_addr); APP_ERROR_CHECK(err_code); }
Edit 1: I tried typecasting and printing the m_ppi_channel enum value and the answer that I got was ZERO. Is that because the assigned channel is Zero? Thanks!