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

Disabling saadc problem

I am using nrf52832, SDK14 and sd 132.5.0. I want to disable SAADC after measuring battery level then enable again when I want to measure it again like in this post. When I try to do that it resets device every time in this handler.

static void battery_level_meas_timeout_handler(void * p_context){

    UNUSED_PARAMETER(p_context);

		static int i=0;
	if(i!=0) //don't initialize twice at the beginning
	{
		nrf_drv_saadc_init(NULL, saadc_event_handler); 
	}
	i=1;
	
    ret_code_t err_code;
    err_code = nrf_drv_saadc_sample();
    APP_ERROR_CHECK(err_code);

	
	nrf_drv_saadc_uninit();

	
	NVIC_ClearPendingIRQ(SAADC_IRQn);

}

How can I solve this problem? Also I am using DFU in my application(May it cause?). This way is working in blinky example, but in my application it resets.

Parents
  • Hi,

    I'm not sure I understand your code. If you uninit the SAADC driver after sampling, you need to init it again before next sample. What is your i=0;, if(i!=0) and i=1; code suppose to do?

    Most likely you are trying to call nrf_drv_saadc_sample when the SAADC driver is not initialized, which will return an error code. When you pass a non-zero error code to APP_ERROR_CHECK, the default recovery method is to reset the chip. Please use this debugging method to check the returned error codes in your application.

    Best regards,

    Jørgen

Reply
  • Hi,

    I'm not sure I understand your code. If you uninit the SAADC driver after sampling, you need to init it again before next sample. What is your i=0;, if(i!=0) and i=1; code suppose to do?

    Most likely you are trying to call nrf_drv_saadc_sample when the SAADC driver is not initialized, which will return an error code. When you pass a non-zero error code to APP_ERROR_CHECK, the default recovery method is to reset the chip. Please use this debugging method to check the returned error codes in your application.

    Best regards,

    Jørgen

Children
Related