Hi,
I have an application that uses the nrfx_saadc driver to measure voltages. One init-function that sets up the saadc and two channels, and one sample-function that calls
void adc_init(void) { nrf_saadc_channel_config_t bat_ch_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0); nrf_saadc_channel_config_t temp_ch_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2); nrfx_saadc_config_t saadc_config = NRFX_SAADC_DEFAULT_CONFIG; nrfx_err_t err_code; /* Battery divider is 147k, needs longer acquisition time */ bat_ch_config.acq_time = NRF_SAADC_ACQTIME_3US; err_code = nrfx_saadc_init(&saadc_config, on_saadc_evt); APP_ERROR_CHECK(err_code); err_code = nrfx_saadc_channel_init(ADC_CH_BAT_SENSE, &bat_ch_config); APP_ERROR_CHECK(err_code); err_code = nrfx_saadc_channel_init(ADC_CH_TEMP_SENSE, &temp_ch_config); APP_ERROR_CHECK(err_code); } uint32_t adc_single_conversion(adc_ch_t channel) { nrf_saadc_value_t value = 0; uint32_t mV; nrfx_err_t err_code; err_code = nrfx_saadc_sample_convert(channel, &value); APP_ERROR_CHECK(err_code); // Without these four lines the base consumption rises by 800 uA nrfx_saadc_channel_uninit(ADC_CH_BAT_SENSE); nrfx_saadc_channel_uninit(ADC_CH_TEMP_SENSE); nrfx_saadc_uninit(); adc_init(); mV = value < 0 ? 0 : value; /* Convert to millivolt */ mV *= 1200; // Bandgap reference mV *= 3; // Voltage prescaler mV /= 1024; // 10-bit measurement NRF_LOG_INFO("ADC ch %d: %d mV (raw: %d)", channel, mV, value); return mV; }