This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problems with the use of ADC at low power

Hi, everyone,

I am pretty new to nRF52 development. Right now,I want to turn SAADC off at low power and turn it back on when wake up, but after  nrfx_saadc_uninit();When I use user_adc_init() again, the SAADC state is always busy.

  • void user_adc_init(void)
    {
    	ret_code_t errCode;
    	user_adc_enable();
        nrf_saadc_channel_config_t channel_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
    
        errCode = nrf_drv_saadc_init(NULL, saadc_callback);
        APP_ERROR_CHECK(errCode);
    
        errCode = nrf_drv_saadc_channel_init(3, &channel_config);
        APP_ERROR_CHECK(errCode);
    
    
    	errCode = nrf_drv_saadc_buffer_convert(m_buffer_pool, 1);
        APP_ERROR_CHECK(errCode);
    
    
    }
    
    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
    	float adcval;
    	ret_code_t err_code;
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
    
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1);
            APP_ERROR_CHECK(err_code);
    			adcval = (float)p_event->data.done.p_buffer[0]*3.6;
        }
    }
    
    void user_adc_read(void)
    {
    	ret_code_t errCode;
    	errCode = nrf_drv_saadc_sample();
    	APP_ERROR_CHECK(errCode);
    }

  • Hello,

    I am pretty new to nRF52 development.

    Welcome!

    Right now,I want to turn SAADC off at low power and turn it back on when wake up, but after  nrfx_saadc_uninit();When I use user_adc_init() again, the SAADC state is always busy.

    First, could you tell me which SDK version you are working with, and whether you are using an nRF52 Development Kit, or a custom board?

    The nrf_drv_saadc_buffer_convert function will return NRF_ERROR_BUSY if SAADC calibration is ongoing, or if the SAADC already is setup with two buffers. Could you ensure that neither of this is the case? It is hard to be sure when only seeing select lines from your code.
    Could you possibly share the entire project's code? That would make spotting issues much easier. Is your application based on an example from the SDK, or code you have found elsewhere?

    Furthermore, I highly recommend triggering the sampling through the NRF_SAADC_TASK_SAMPLE task through PPI, rather than calling nrf_drv_saadc_sample every sample. I would also recommend that you do not use magic numbers in your code, to save yourself from a lot of troubles down the line, in your programming career! Slight smile

    Looking forward to resolving this issue together!

    Best regards,
    Karl

Related