Skip to content

Current calibration

Pavel S edited this page May 29, 2021 · 1 revision

Run following code in order to calibrate flow current for battery gauge. Apply 100mA load (or adjust this values in the code below) between "battery+" and GND (not "battery-")

#include "mbed.h"
#include "BQ35100.h"

BQ35100 gauge(GAUGE_ENABLE_PIN);
I2C i2c(I2C_SDA, I2C_SCL);

int main() {
    if (gauge.init(&i2c)) {
        debug("Init OK\n");

    } else {
        debug("Could not init the gauge\n");
        return 0;
    }

    ThisThread::sleep_for(5s);

    if (gauge.setSecurityMode(BQ35100::SECURITY_UNSEALED)) {
        debug("Device unsealed\n");

    } else {
        debug("Unseal failed\n");
        return 0;
    }

    ThisThread::sleep_for(1s);

    if (gauge.setGaugeMode(BQ35100::ACCUMULATOR_MODE)) {
        debug("Gauge mode set\n");

    } else {
        debug("Set gauge mode failed\n");
        return 0;
    }

    ThisThread::sleep_for(1s);

    if (gauge.startGauge()) {
        debug("Gauge started\n");

    } else {
        debug("Could not start the gauge\n");
        return 0;
    }

    debug("Apply 100mA current within next 10s\n");

    ThisThread::sleep_for(10s);

    if (gauge.calibrateCurrent(100)) { // mA
        debug("Current calibration successful\n");

    } else {
        debug("Current calibration failed\n");
        return 0;
    }

    debug("Done\n");

    gauge.setSecurityMode(BQ35100::SECURITY_SEALED);
}
Clone this wiki locally