如何检测电池电量,有例程源码参考吗?



  • 如何检测电池电量,有例程源码参考吗?



  • This post is deleted!


  • 在driver_adc.h中,有说明:
    USAGE SAMPLE
    1. get vbat value
    struct adc_cfg_t cfg;
    uint16_t result, ref_vol;

        memset((void*)&cfg, 0, sizeof(cfg));
        cfg.src = ADC_TRANS_SOURCE_VBAT;
        cfg.ref_sel = ADC_REFERENCE_INTERNAL;
        cfg.int_ref_cfg = ADC_INTERNAL_REF_1_2;
        cfg.clk_sel = ADC_SAMPLE_CLK_24M_DIV13;
        cfg.clk_div = 0x3f;
        adc_init(&cfg);
        adc_enable(NULL, NULL, 0);
    
        adc_get_result(ADC_TRANS_SOURCE_VBAT, 0, &result);
    	ref_vol = adc_get_ref_voltage(ADC_REFERENCE_INTERNAL);
        // vbat_vol = (result * 4 * ref_vol) / 1024 mV.