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

How to check SAADC is enabled?

Hello,

I would like to know how I can check whether the SAADC is enabled or nor on my application. I am disabling the SAADC with nrf_drv_saadc_uninit(); after configuring it, however when my interruption is triggered to sample it seems that the saadc is not started so I would like to check if that's right or not.

Thanks in advance,

Parents
  • Hi,

    You can check if the SAADC peripheral is enabled by calling the HAL function nrf_saadc_enable_check(), but from your question I'm not sure this is what you want.

    If you call nrf_drv_saadc_uninit(), the SAADC driver will be uninitialized, and the peripheral will be disabled. If you try to sample after this, without calling nrf_drv_saadc_init(), you will get an error code.

    Best regards,

    Jørgen

  • That depends on if you have uninited the SAADC. I suggest you use a flag to know when you have inited/uninited the SAADC, like this:

    static uint8_t saadc_is_initialized = false;
    
    uint32_t initialize_saadc()
    {
    	uint32_t err_code;
    	err_code = nrf_drv_saadc_init();
    	if(err_code != NRF_SUCCESS)
    	{
    		return err_code;
    	}
    	err_code = nrf_drv_saadc_buffer_convert();
    	if(err_code != NRF_SUCCESS)
    	{
    		return err_code;
    	}
    	saadc_is_initialized = true;
    	return err_code;
    }
    
    void uninitialize_saadc()
    {
    	nrf_drv_saadc_uninit();
    	saadc_is_initialized = false;
    }
    
    void battery_timer_handler()
    {
    	uint32_t err_code;
    	
    	if(!saadc_is_initialized)
    	{
    		err_code = initialize_saadc();
    		APP_ERROR_CHECK(err_code);
    	}
    	
    	err_code = nrf_drv_saadc_sample();
    	APP_ERROR_CHECK(err_code);
    }
    
    void power_manager()
    {
    	if(saadc_is_initialized)
    	{
    		uninitialize_saadc();
    	}
    	
    	// Go to sleep
    	__WFE();
    	__SEV();
    	__WFE();
    }
    
Reply
  • That depends on if you have uninited the SAADC. I suggest you use a flag to know when you have inited/uninited the SAADC, like this:

    static uint8_t saadc_is_initialized = false;
    
    uint32_t initialize_saadc()
    {
    	uint32_t err_code;
    	err_code = nrf_drv_saadc_init();
    	if(err_code != NRF_SUCCESS)
    	{
    		return err_code;
    	}
    	err_code = nrf_drv_saadc_buffer_convert();
    	if(err_code != NRF_SUCCESS)
    	{
    		return err_code;
    	}
    	saadc_is_initialized = true;
    	return err_code;
    }
    
    void uninitialize_saadc()
    {
    	nrf_drv_saadc_uninit();
    	saadc_is_initialized = false;
    }
    
    void battery_timer_handler()
    {
    	uint32_t err_code;
    	
    	if(!saadc_is_initialized)
    	{
    		err_code = initialize_saadc();
    		APP_ERROR_CHECK(err_code);
    	}
    	
    	err_code = nrf_drv_saadc_sample();
    	APP_ERROR_CHECK(err_code);
    }
    
    void power_manager()
    {
    	if(saadc_is_initialized)
    	{
    		uninitialize_saadc();
    	}
    	
    	// Go to sleep
    	__WFE();
    	__SEV();
    	__WFE();
    }
    
Children
No Data
Related