Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can't stop SAADC

Hi,

When I try to stop ADC sampling, the adc driver keeps on busy. The function nrf_drv_saadc_is_busy() keeps returning true.

I looked in other posts (like this one) and found that this is the way to start and stop ADC:

void start_adc()
{
    saadc_sampling_event_init();
    saadc_init();
    saadc_sampling_event_enable();
}

void stop_adc()
{
	nrf_drv_timer_disable(&m_timer);
	nrf_drv_ppi_channel_disable(m_ppi_channel);
	while(nrf_drv_saadc_is_busy()); //--> always true
	nrf_drv_saadc_uninit();
}

But this is not working because while(nrf_drv_saadc_is_busy()); keeps returning true.

I'm using SDK 14 with double buffer and ble communication.

I read also this post and understood that it might be because of the double buffer. So I tried disabling it by:

1. Changing static nrf_saadc_value_t m_buffer_pool[2][SAADC_SAMPLES_IN_BUFFER] to static nrf_saadc_value_t m_buffer_pool[1][SAADC_SAMPLES_IN_BUFFER]

2. Deleting the following from saadc_init():

err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);

and left only with:

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);

Am I doing this correctly?

Thanks!

Parents
  • Hi,

    The SAADC driver will always be in the busy state when a buffer is setup for conversion (by calling nrf_drv_saadc_buffer_convert). It will not help to only disable double buffering, you also need to remove the second buffer.

    You have two alternatives:

    1. Call nrf_drv_saadc_abort to remove the buffers and stop any ongoing sampling. This will trigger the STOP task and put the driver in IDLE state when STOPPED event is received.
    2. Disable double buffering, as you describe above, and only call stop_adc in your SAADC event handler when you receive a DONE event, but before you call nrf_drv_saadc_buffer_convert to setup the buffer for conversion again.

    Best regards,
    Jørgen

  • nrf_drv_saadc_abort should stop the SAADC and any ongoing conversions, but if you are setting up new buffers and triggering sampling, you will still get callbacks. You should check the error codes from nrf_drv_timer_disable and nrf_drv_ppi_channel_disablein stop_adc, to make sure the sampling is actually stopped, before aborting and uninitializing the SAADC.

    Error 133 (0x0085) means NRF_ERROR_MODULE_ALREADY_INITIALIZED. If do not uninit the PPI driver, it would be expected that you get this error when calling nrf_drv_ppi_init.

Reply
  • nrf_drv_saadc_abort should stop the SAADC and any ongoing conversions, but if you are setting up new buffers and triggering sampling, you will still get callbacks. You should check the error codes from nrf_drv_timer_disable and nrf_drv_ppi_channel_disablein stop_adc, to make sure the sampling is actually stopped, before aborting and uninitializing the SAADC.

    Error 133 (0x0085) means NRF_ERROR_MODULE_ALREADY_INITIALIZED. If do not uninit the PPI driver, it would be expected that you get this error when calling nrf_drv_ppi_init.

Children
Related