The BQ25895M is switch mode battery charge management and system power path management device for single cell Li-Ion and Li-polymer batteries. It supports high input voltage fast charging and communicates over an I2C serial interface.
To add this library to your project, add the following to the top of your device code:
#require "BQ25895M.lib.nut:1.0.0"
The class’ constructor takes one required parameter (a configured imp I²C bus) and an optional parameter (the I²C address of the BQ25895M. The I²C address must be the address of your chip or an I²C error will be thrown.
Parameter | Type | Required | Description |
---|---|---|---|
i2cBus | i2c bus object | Yes | The imp i2c bus that the BQ25895M is wired to. The i2c bus must be preconfigured. The library will not configure the bus. |
i2cAddress | integer | No | The i2c address of the BQ25895M. Default value is 0x6A |
None.
local i2c = hardware.i2cKL
i2c.configure(CLOCK_SPEED_400_KHZ);
batteryCharger <- BQ25895M(i2c);
Initializes the battery charger with default settings.
None.
None.
// Initializes charger with default settings
batteryCharger.setDefaults();
Enables the device to automatically perform a charging cycle when a battery is connected and an input source is available.
None.
None.
// Enables charging
batteryCharger.enableCharging();
Disables charging capabilities from the device. The device will not charge until enableCharging() is called again.
None.
None.
// Disables charging
batteryCharger.disableCharging();
This method sets the fast charge current limit.
The default fast charge current limit is 2048mA.
Parameter | Type | Required | Description |
---|---|---|---|
currentLimit | Integer | Yes | The desired fast charge current limit in milli Amps (0 - 5056mA) |
None.
// Sets the fast charge current limit to 5056mA
batteryCharger.setChargeCurrent(5056);
This method sets the desired battery voltage that the device should charge to.
The default charge voltage is 4352 mV.
Parameter | Type | Required | Description |
---|---|---|---|
chargeVoltage | Integer | Yes | The desired charge voltage in milli Volts (3840 - 4608mV) |
None.
// Sets the charge voltage to 4200mV
batteryCharger.setChargeVoltage(4200);
Returns the target battery charge voltage
None.
Integer — The voltage in milli volts.
local voltage = batteryCharger.getChargeVoltage();
server.log("Voltage: " + voltage + "mV");
Returns the current battery voltage based on the internal ADC conversion.
None.
Integer — The battery voltage in milli volts.
local voltage = batteryCharger.getBatteryVoltage();
server.log("Voltage: " + voltage + "mV");
Returns the VBUS voltage based on the ADC conversion, this is the input voltage
None.
Integer — The battery voltage in milli volts.
local voltage = batteryCharger.getVBUSVoltage();
server.log("Voltage: " + voltage + "mV");
Returns the system voltage based on the ADC conversion, this the output voltage which can be used to power other chips in your application
None.
Integer — The battery voltage in milli volts.
local voltage = batteryCharger.getSystemVoltage();
server.log("Voltage: " + voltage + "mV");
Returns the measured current going to the battery
None.
Integer — The charging current in milli Amps.
local current = batteryCharger.getChargingCurrent();
server.log("Current: " + current + "mA");
Returns the charging status
None.
Integer — see table below for supported values.
Charging Status Constant | Value |
---|---|
BQ25895M_CHARGING_STATUS.NOT_CHARGING | 0x00 |
BQ25895M_CHARGING_STATUS.PRE_CHARGE | 0x08 |
BQ25895M_CHARGING_STATUS.FAST_CHARGE | 0x10 |
BQ25895M_CHARGING_STATUS.CHARGE_TERMINATION_DONE | 0x18 |
local status = charger.getChargingStatus();
switch(status) {
case BQ25895M_CHARGING_STATUS.NOT_CHARGING :
// Do something
break;
case BQ25895M_CHARGING_STATUS.PRE_CHARGE :
// Do something
break;
case BQ25895M_CHARGING_STATUS.FAST_CHARGING :
// Do something
break;
case BQ25895M_CHARGING_STATUS.CHARGE_TERMINATION_DONE :
// Do something
break;
}
Returns the possible charger faults
None.
Table — the possible charger faults
Fault | Type | Description |
---|---|---|
watchdogFault | Bool | true if watchdog timer has expired |
boostFault | Bool | true if VBUS overloaded in OTG, VBUS OVP, or battery is too low |
chrgFault | Integer | see table below for possible values |
battFault | Bool | true if VBAT > VBATOVP |
ntcFault | Integer | see table below for possible values |
CHRG_FAULT has an enumerated type to match its output.
Charging Fault | Value |
---|---|
BQ25895M_CHARGING_FAULT.NORMAL | 0x00 |
BQ25895M_CHARGING_FAULT.INPUT_FAULT | 0x01 |
BQ25895M_CHARGING_FAULT.THERMAL_SHUTDOWN | 0x02 |
BQ25895M_CHARGING_FAULT.CHARGE_SAFETY_TIMER_EXPIRATION | 0x03 |
NTC_FAULT has an enumerated type to match its output.
NTC Fault | Value |
---|---|
BQ25895M_NTC_FAULT.NORMAL | 0x00 |
BQ25895M_NTC_FAULT.TS_COLD | 0x01 |
BQ25895M_NTC_FAULT.TS_HOT | 0x02 |
local faults = batteryCharger.getChargerFaults();
server.log("Watchdog Fault = " + faults.watchdogFault);
server.log("Boost Fault = " + faults.boostFault);
switch(faults.chrgFault) {
case BQ25895M_CHARGING_FAULT.NORMAL:
// Do something
break;
case BQ25895M_CHARGING_FAULT.INPUT_FAULT:
// Do something
break;
case BQ25895M_CHARGING_FAULT.THERMAL_SHUTDOWN:
// Do something
break;
case BQ25895M_CHARGING_FAULT.CHARGE_SAFETY_TIMER_EXPIRATION:
// Do something
break;
}
server.log("Battery Fault = " + faults.battFault);
switch(faults.ntcFault) {
case BQ25895M_NTC_FAULT.NORMAL:
// Do something
break;
case BQ25895M_NTC_FAULT.TS_COLD:
// Do something
break;
case BQ25895M_NTC_FAULT.TS_HOT:
// Do something
break;
Restores the devices default settings
None.
None.
batteryCharger.reset();