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

saadc - switch channel on demand

I am using a nRF52 and I have to measure two voltages:

  1. the first continuously

  2. when a command is received, the second voltage have to be measured and then switch back to measure the first

I initialize the saadc driver, configure two channels, initialize the first (nrf_drv_saadc_channel_init) then I start a timer. When the timer fires I call the nrf_drv_saadc_sample() to acquire the voltage in the saadc callback. Everything works as expected.

Problems arise when I try to switch to the second channel. On command received, I stop the timer and I try to switch to the second channel:

    err_code = nrf_drv_saadc_channel_uninit(1);
    if (err_code == NRF_ERROR_BUSY) {
      NRF_LOG_DEBUG("\tBUSY on uninit\n");
    }
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_channel_init(0, &ch2_config);
    if (err_code == NRF_ERROR_BUSY) {
      NRF_LOG_DEBUG("\tBUSY on init\n");
    }
    APP_ERROR_CHECK(err_code);

I always get NRF_ERROR_BUSY calling nrf_drv_saadc_channel_uninit(1).

What's the right way to switch between channels?

I have seen a lot of examples on measuring two or more voltages but they switch between channels one after the other.

Thank you in advance.

Related