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

  • Hi Jorgen,

    Thanks for the reply.

    I prefer to keep the double buffer so I tried the abort method. Calling nrf_drv_saadc_abort() alone doesn't stop the adc callback. It keeps triggering with constant value 1024. And then if I call my function start_system() again, I get a hard fault from nrf_drv_ppi_init() (133 error).

    I also tried calling nrf_drv_saadc_uninit() after aborting - this did stop the callback, but I got the same hard fault (133)

Reply
  • Hi Jorgen,

    Thanks for the reply.

    I prefer to keep the double buffer so I tried the abort method. Calling nrf_drv_saadc_abort() alone doesn't stop the adc callback. It keeps triggering with constant value 1024. And then if I call my function start_system() again, I get a hard fault from nrf_drv_ppi_init() (133 error).

    I also tried calling nrf_drv_saadc_uninit() after aborting - this did stop the callback, but I got the same hard fault (133)

Children
No Data
Related