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

battery level percentage for nrf52832

I am new to nrf52832. I am using pcaboard10040 ,sdk12.3.0 and softdevice s132. I am using  battery_level_in_percent function for calculating percentage level of battery. But every time I got 100% level on nrfconnect app.But actual voltage I measured on multimeter is 2.6v

Thanks in Advance.

  • Hi,

    {len, datatype, data}

    {0x02, 0xFF,   0x64}

    This is my packet through which i am sending updated battery status using battery_level_in_percent api, no external power is used, nrf is running only on battery CR 2032 3v. 

    code snippet for battery calculation as following.

    
    #define ADC_REF_VOLTAGE_IN_MILLIVOLTS     600                                          /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
    #define ADC_PRE_SCALING_COMPENSATION      6                                            /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
    #define DIODE_FWD_VOLT_DROP_MILLIVOLTS    270                                          /**< Typical forward voltage drop of the diode that is connected in series with the voltage supply. This is the voltage drop when the forward current is 1mA. Source: Data sheet of 'SURFACE MOUNT SCHOTTKY BARRIER DIODE ARRAY' available at www.diodes.com. */
    #define ADC_RES_8BIT                     255   
    
    #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
            ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / ADC_RES_8BIT) * ADC_PRE_SCALING_COMPENSATION)
    
    void battery_level_get_callback(nrf_drv_saadc_evt_t const * p_event)
    {
    				nrf_saadc_value_t adc_result;
            uint16_t          batt_lvl_in_milli_volts;
           
    			
            adc_result = p_event->data.done.p_buffer[0];
    
        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_lvl_in_milli_volts=ADC_RESULT_IN_MILLI_VOLTS(adc_result) +
                                      DIODE_FWD_VOLT_DROP_MILLIVOLTS;
    			
    				percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts);
    			
    			
    				nrf_drv_saadc_uninit();
            NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos);
            NVIC_ClearPendingIRQ(SAADC_IRQn);
        }
    }
    
    
    
    void saadc_init(void)
    {
        ret_code_t err_code;
    	  err_code = nrf_drv_saadc_init(NULL, battery_level_get_callback);
        APP_ERROR_CHECK(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_channel_init(0, &channel_config);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    	
    		
    }
    

  • I am assuming {0x02, 0xFF,   0x64} is an advertising packet and not a BLE service. How are you updating your advertising packet? I recommend you stop your advertising (SD_BLE_GAP_ADV_STOP), setting the advertising data again (SD_BLE_GAP_ADV_DATA_SET), then restarting the advertising (SD_BLE_GAP_ADV_START)

    Best regards,

    Simon

  • Hi ,

    I am updating advertising packet on radio notification. Whenever radio is active, I  updated data.

  • Hi

    You will have to stop the advertising using sd_ble_gap_adv_stop(), run advertising_init() with your new data, and advertising_start() every time you want to change your advertising data. 

    Best regards,

    Simon

  • I have stop advertising  using sd_ble_gap_adv_stop(), run advertising_init() with your new data, and advertising_start() every time you want to change your advertising data. but battery level is 100

Related