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

nRF52 SAADC re-initialize

Hi guys! Got a problem with re-initialising my SAADC to read my current battery voltage. I'm using SDK11 and don't want to migrate to v12, so I wanted to do a workaround for the power consumption bug when using SAADC and going to sleep.

I'm initialising the SAADC

void saadc_init(void)
{
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);	
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_channel_init(0, &channel_config);
APP_ERROR_CHECK(err_code);

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

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

my Callback looks like this

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{	
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, SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);

batt_val[0]=	p_event->data.done.p_buffer[0];
nrf_drv_saadc_uninit();
NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
NVIC_ClearPendingIRQ(SAADC_IRQn);			
}

}

But when I want to re-initialise the SAADC before taking a new measurement via nrf_drv_saadc_sample(); by calling the saadc_init(); again, my controller seems to freeze and connecting via BLE isn't possible anymore. Is the SAADC not properly uninitialized so a Re-Initializing breaks my execution? Any suggestions how to fix this? Implementation seems alright to me. Using Segger Studio with GCC btw.

Parents Reply Children
Related