|
| 1 | +# BQ27220 |
| 2 | + |
| 3 | +The [BQ27220](https://www.ti.com/product/BQ27220) is a single-cell Li-Ion battery fuel gauge IC that provides precise battery status monitoring, including state of charge (SoC), remaining capacity, state of health (SoH), and other critical parameters. This component provides a driver implementation for the BQ27220 in embedded systems, supporting communication via the I2C interface with the host controller. |
| 4 | + |
| 5 | +In addition to the basic functionality, the component also include a tool [sample-data-app](tools/sample-data-app), which can be used to monitor the battery status in real-time and print data with CSV format for Gauging Parameter Calculator. |
| 6 | + |
| 7 | +## Example of usage |
| 8 | + |
| 9 | +``` c |
| 10 | + |
| 11 | +#define I2C_MASTER_SCL_IO GPIO_NUM_1 /*!< gpio number for I2C master clock */ |
| 12 | +#define I2C_MASTER_SDA_IO GPIO_NUM_2 /*!< gpio number for I2C master data */ |
| 13 | + |
| 14 | +// Default Gauging Parameter |
| 15 | +static const parameter_cedv_t default_cedv = { |
| 16 | + .full_charge_cap = 650, |
| 17 | + .design_cap = 650, |
| 18 | + .reserve_cap = 0, |
| 19 | + .near_full = 200, |
| 20 | + .self_discharge_rate = 20, |
| 21 | + .EDV0 = 3490, |
| 22 | + .EDV1 = 3511, |
| 23 | + .EDV2 = 3535, |
| 24 | + .EMF = 3670, |
| 25 | + .C0 = 115, |
| 26 | + .R0 = 968, |
| 27 | + .T0 = 4547, |
| 28 | + .R1 = 4764, |
| 29 | + .TC = 11, |
| 30 | + .C1 = 0, |
| 31 | + .DOD0 = 4147, |
| 32 | + .DOD10 = 4002, |
| 33 | + .DOD20 = 3969, |
| 34 | + .DOD30 = 3938, |
| 35 | + .DOD40 = 3880, |
| 36 | + .DOD50 = 3824, |
| 37 | + .DOD60 = 3794, |
| 38 | + .DOD70 = 3753, |
| 39 | + .DOD80 = 3677, |
| 40 | + .DOD90 = 3574, |
| 41 | + .DOD100 = 3490, |
| 42 | +}; |
| 43 | + |
| 44 | +// Default Gauging Config |
| 45 | +static const gauging_config_t default_config = { |
| 46 | + .CCT = 1, |
| 47 | + .CSYNC = 0, |
| 48 | + .EDV_CMP = 0, |
| 49 | + .SC = 1, |
| 50 | + .FIXED_EDV0 = 0, |
| 51 | + .FCC_LIM = 1, |
| 52 | + .FC_FOR_VDQ = 1, |
| 53 | + .IGNORE_SD = 1, |
| 54 | + .SME0 = 0, |
| 55 | +}; |
| 56 | + |
| 57 | +static i2c_bus_handle_t i2c_bus = NULL; |
| 58 | +static bq27220_handle_t bq27220 = NULL; |
| 59 | + |
| 60 | +i2c_config_t conf = { |
| 61 | + .mode = I2C_MODE_MASTER, |
| 62 | + .sda_io_num = I2C_MASTER_SDA_IO, |
| 63 | + .sda_pullup_en = GPIO_PULLUP_ENABLE, |
| 64 | + .scl_io_num = I2C_MASTER_SCL_IO, |
| 65 | + .scl_pullup_en = GPIO_PULLUP_ENABLE, |
| 66 | + .master.clk_speed = 400 * 1000, |
| 67 | +}; |
| 68 | +i2c_bus = i2c_bus_create(I2C_NUM_0, &conf); |
| 69 | + |
| 70 | +bq27220_config_t bq27220_cfg = { |
| 71 | + .i2c_bus = i2c_bus, |
| 72 | + .cfg = &default_config, |
| 73 | + .cedv = &default_cedv, |
| 74 | +}; |
| 75 | +bq27220 = bq27220_create(&bq27220_cfg); |
| 76 | + |
| 77 | +``` |
0 commit comments