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

NRF52832 SAADC current issue

Hi engineer,

I found that the SAADC current is increased after the SAADC function opened, then my processing method as below:

1,I close SAADC function after sampling SAADC data in below code:

nrf_drv_saadc_uninit();
NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
NVIC_ClearPendingIRQ(SAADC_IRQn);

2,I initialized SAADC function in below code before sampling SAADC data:

err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
nrf_saadc_channel_config_t channel_battery_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
nrf_saadc_channel_config_t channel_sensor_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);	
err_code = nrf_drv_saadc_channel_init(0, &channel_battery_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(1, &channel_sensor_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);

3,The SAADC is cycle sampling ,its interval time is 3ms;

My question:

1,when the sensor device is set 3ms cycle sampling time,the APP on mobile phone can't find the sensor device;

2,when the sensor device is set 10s cycle sampling time,the APP on mobile phone can find the sensor device and system run nomally;

how to handle the issue?

thanks!

  • Which SDK version are you using? Are you running BLE application?

  • Which BLE application are you running? Are you basing it on one of the SDK examples? Is your issue with the current or that your device is not advertising when you set the sample time to 3 ms? Have you tried anything between 3 ms and 10 s? Are you checking error codes on any function calls to see why your application is not advertising? Could you upload a complete example showing your issue?

  • what I am appplication of running is ble_ant_app_hrm(multiprotocol:BLE&ANT);I develop project base on the application,I have tried to set between 3ms to 10s for test ,but 10s is more stable than other time ,the longer the better;I have done many method to look for the issue ,but I yet don't look for until now;below is part of my code:

    int main(void)
    {
        uint32_t err_code;
        sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
    	
        err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
        
        // Initialize time
         timers_init();
    
       // initialize saadc
         saadc_init();
    	
       // Initialize S332 SoftDevice
         ble_ant_stack_init();
    
       //ANT data send setup
         ant_data_send_setup();
    	
        // Initialize Bluetooth stack parameters.
        gap_params_init();
        advertising_init();
        services_init();
        conn_params_init();
       
       //ant profile setup
        profile_setup();
          
    #ifdef BONDING_ENABLE
        bool erase_bonds;
    
        peer_manager_init(erase_bonds);
        if (erase_bonds == true)
        {
            NRF_LOG_INFO("Bonds erased!\r\n");
        }
    #endif // BONDING_ENABLE
        application_timers_start();
        ant_and_adv_start();
    
        // Enter main loop.
        for (;;)
        {
          power_manage();
        }
    }
    
    
    static void timers_init(void)
    {
        // Initialize timer module
          APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
    	  
       //adc sampling time module
          app_timer_create(&m_AD_sample_timer_id,
                         APP_TIMER_MODE_REPEATED,
                         AD_sample_meas_timeout_handler);
    }
    
    //adc sampling time setup
    static void application_timers_start(void)
    {
        uint32_t err_code;
    	
    	 //interval time is 3ms
    	  err_code = app_timer_start(m_AD_sample_timer_id, AD_SAMPLE_MEAS_INTERVAL, NULL);
        APP_ERROR_CHECK(err_code);
    	
    }
    
    //saadc init
    void saadc_init(void)
    {
    	 ret_code_t err_code;
        err_code = nrf_drv_saadc_init(NULL, saadc_callback);
        APP_ERROR_CHECK(err_code);
    	
        nrf_saadc_channel_config_t channel_battery_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
    	
        nrf_saadc_channel_config_t channel_sensor_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
    	
        err_code = nrf_drv_saadc_channel_init(0, &channel_battery_config);
        APP_ERROR_CHECK(err_code);
    		
        err_code = nrf_drv_saadc_channel_init(1, &channel_sensor_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);
    }
    
    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
    	 int i;
    	 float offset=-0.025;
        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);
            for (i = 0; i < SAMPLES_IN_BUFFER; i++)
            {
    		      AD_temp_check[i]=p_event->data.done.p_buffer[i];
            }
    				
    		nrf_drv_saadc_uninit();
                    NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
                    NVIC_ClearPendingIRQ(SAADC_IRQn);
    }
    
    static void AD_sample_meas_timeout_handler(void * p_context)
    {
        UNUSED_PARAMETER(p_context);
        saadc_init();
        nrf_drv_saadc_sample();
    }
    
  • Not really a more working example you provided here. It is hard to debug your application without seeing the whole application and being able to run it. I managed to include your code into the BLE/ANT example, but it stop advertising on the timer event. If I alter the program to not uninit/init the SAADC on each timer event, the code works fine. I'm not sure what is the problem with your application unless you can provide a working example project, showing this issue.

Related