Hi,
I have the simplest of SAADC sampling scenarios whereby I'm sampling a voltage in a one-off manner, nrf_drv_saadc_init, nrf_drv_saadc_channel_init, nrf_drv_saadc_sample_convert, and then nrf_drv_saadc_abort and nrf_drv_saadc_uninit, but the system will simply not go to sleep after sd_app_evt_wait which returns immediately.
If I don't call the nrf_drv_saadc_sample_convert within the function, maintaining all of the other existing saadc code around it, then sd_app_evt_wait properly sleeps.
Any idea?
Thx!
void BatteryMonitor::SingleSampleRequest() { ret_code_t err_code; nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0); channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL; //Set internal reference of fixed 0.6 volts channel_config.gain = NRF_SAADC_GAIN1_6; //Set input gain to 1/6. The maximum SAADC input voltage is then 0.6V/(1/6)=3.6V. The single ended input range is then 0V-3.6V channel_config.acq_time = NRF_SAADC_ACQTIME_10US; //Set acquisition time. Set low acquisition time to enable maximum sampling frequency of 200kHz. Set high acquisition time to allow maximum source resistance up to 800 kohm, see the SAADC electrical specification in the PS. channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED; //Set SAADC as single ended. This means it will only have the positive pin as input, and the negative pin is shorted to ground (0V) internally. channel_config.pin_p = NRF_SAADC_INPUT_AIN0; //Select the input pin for the channel. AIN0 pin maps to physical pin P0.02. channel_config.pin_n = NRF_SAADC_INPUT_DISABLED; //Since the SAADC is single ended, the negative pin is disabled. The negative pin is shorted to ground internally. channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED; //Disable pullup resistor on the input pin channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED; //Disable pulldown resistor on the input pin nrf_drv_saadc_config_t saadc_config; saadc_config.low_power_mode = false; //Enable low power mode. saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT; //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=2048 (when input voltage is 3.6V for channel gain setting of 1/6). saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED; // NRF_SAADC_OVERSAMPLE_4X; //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times. saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW; //Set SAADC interrupt to low priority. err_code = nrf_drv_saadc_init(&saadc_config, SAADC_Callback); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_channel_init(0, &channel_config); APP_ERROR_CHECK(err_code); nrf_saadc_value_t adcValue; ret_code_t ret_code = nrf_drv_saadc_sample_convert(0, &adcValue); if (ret_code == NRF_SUCCESS) { m_milliVolts = (uint16_t)((float) adcValue * VBAT_MV_PER_LSB * VBAT_DIVIDER_COMP); m_percentage = VoltToPercent(m_milliVolts); NRF_LOG_INFO("MV %d - %dpct", m_milliVolts, m_percentage); } nrf_drv_saadc_abort(); nrf_drv_saadc_uninit(); while (nrf_drv_saadc_is_busy()) ; }