Hi,
I am developing my application on top of low power node example available nrf sdk for mesh v5.0.0. The idea behind the application is that after the node is provisioned and model publication is set, node should periodically measure battery voltage, calculate battery percentage and send the values over mesh to the desired address set in model publication state and return to the idle state. In idle state after provisioning, the node consumes only around 70ua. But after reading adc value using saadc in blocking mode, the node is constantly consuming 3.4 ma and not returning to the idle state. I am guessing that the CPU is not going back to sleep after reading battery voltage and SAADC is keeeping the CPU awake. Can someone help me to complletely disable the SAADC peripheral?
I am attaching the routine which I use to initialize and deinitialize the SAADC peripheral before and after reading ADC value and also the routine to read ADC value. Thanks!
//Initialization routine void saadc_init(void) { nrfx_err_t err_code; ret_code_t ret_code; nrf_drv_saadc_config_t saadc_config_t; saadc_config_t.resolution = NRF_SAADC_RESOLUTION_12BIT; saadc_config_t.oversample = NRF_SAADC_OVERSAMPLE_DISABLED; saadc_config_t.low_power_mode = true; saadc_config_t.interrupt_priority = APP_IRQ_PRIORITY_LOW; nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5); //err_code = nrf_drv_saadc_init(NULL, saadc_callback_handler); //APP_ERROR_CHECK(err_code); //err_code = nrfx_saadc_channel_init(0, &channel_config); //APP_ERROR_CHECK(err_code); NRF_LOG_INFO("Initializing channel"); ret_code = nrf_drv_saadc_init(&saadc_config_t, NULL); APP_ERROR_CHECK(ret_code); if(ret_code == NRFX_SUCCESS) NRF_LOG_INFO("Initialized channel"); NRF_LOG_INFO("Enabling Channel"); err_code = nrfx_saadc_channel_init(0, &channel_config); APP_ERROR_CHECK(err_code); if(err_code == NRFX_SUCCESS) NRF_LOG_INFO("Enabled channel"); } //Deinitialization routine void saadc_deinit(void) { nrfx_err_t err_code; NRF_LOG_INFO("Disabling Channel"); err_code = nrfx_saadc_channel_uninit(0); APP_ERROR_CHECK(err_code); NRF_LOG_INFO("Disabled channel"); NRF_LOG_INFO("Uninitializing channel"); nrf_drv_saadc_uninit(); NRF_LOG_INFO("Deinitialized channel"); } //Reading ADC value in blocking mode void readBtryVtg(void) { nrfx_err_t err = NRF_SUCCESS; for(uint8_t sample=0; sample < NO_OF_ADC_SAMPLES; sample++) { err = nrfx_saadc_sample_convert(0, &adcVal); adcValSum += adcVal; } adcValAvg = adcValSum / NO_OF_ADC_SAMPLES; adcValAvg *= 2; btryVtgAvg = ((adcValAvg * (3.6 / 4096)) * 1000); btryVtgAvg = (btryVtgAvg > 2999) ? 2999 : btryVtgAvg; btryVtgMap = (((float)(btryVtgAvg/1000.0) - MIN_BTRY_VTG) / (MAX_BTRY_VTG - MIN_BTRY_VTG)); NRF_LOG_INFO("ADC val - %d\r\n",adcValAvg); NRF_LOG_INFO("Battery voltage mapped " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(btryVtgMap)); }