SLUUBD4A April 2016 – November 2022 BQ27220
The following example shows the command sequence needed to modify a Data Memory parameter in RAM. For this example, the default Design Capacity is updated from 3000 mAh to 1200 mAh. All device writes (wr) and reads (rd) refer to the I2C 8-bit addresses 0xAA and 0XAB, respectively. The address 0x3E is used to make changes to RAM, as these changes cannot be made to a given parameter's direct address. This ensures that the RAM does not get corrupted upon an incorrect write.
Step | Description | Pseudo Code |
---|---|---|
1 | If the device has been previously SEALED, UNSEAL it by sending the appropriate keys to Control() (0x00 and 0x01). | //Two-byte incremental method wr 0x00 0x14 0x04; wr 0x00 0x72 0x36; //Alternative single byte method wr 0x00 0x14; wr 0x01 0x04; wr 0x00 0x72; wr 0x01 0x36; |
2 | The BQ27220 boots up in UNSEAL, but not in FULL ACCESS. Enter FULL ACCESS to gain access to the Data Memory. | //Two-byte incremental method wr 0x00 0xFF 0xFF; wr 0x00 0xFF 0xFF; //Alternative single byte method wr 0x00 0xFF; wr 0x01 0XFF; wr 0x00 0xFF; wr 0x01 0xFF; |
3 | Send ENTER_CGF_UPDATE command (0x0090). | wr 0x00 0x90 0x00; |
4 | Confirm CFGUPDATE mode by polling OperationStatus() register until bit 2 is set. May take up to 1 second. | rd 0x3B OperationStatus(); |
5 | Write 0x9F to 0x3E to access the MSB of Design Capacity. | wr 0x3E 0X9F; |
6 | Write 0x92 to 0x3F to access the LSB of Design Capacity. | wr 0x3F 0X92; |
7 | Read the 1-byte checksum using MACDataSum() command (0x60). | rd 0x60 Old_Chksum; |
8 | Read the 1-byte block length using the MACDataLen() command (0x61). | rd 0x61 Data_len; |
9 | Read both Design Capacity bytes starting at 0x40. | rd 0x40 Old_DC_MSB; rd 0x41 Old_DC_LSB; |
10 | Write both Design Capacity bytes starting at 0x40. For this example, the new value is 1200 mAh. (0x04B0 in hex) | wr 0x40 0x04; wr 0X41 0XB0; |
11 | Calculate the new checksum. The checksum is (255 – x) where x is the 8-bit summation of the BlockData() (0x40 to 0x5F) on a byte-by-byte basis. A quick way to calculate the new checksum uses a data replacement method with the old and new data summation bytes. Refer to the code for the indicated method. | Temp = mod(255 – Old_Chksum – OLD_DC_MSB – OLD_DC_LSB, 256); New_Chksum = 255 – mod(temp + 0x04 + 0Xb0, 256); |
12 | Write new checksum. For this example, New_Chksum is 0XB0; | wr 0x60 New_Chksum; //Example: wr 0x60 0XB0; |
13 | Write the block length. The data is actually transferred to the RAM when the correct checksum and length for the whole block is written. For this example, Data_len is 0x24; | wr 0x61 Data_len; //Example: wr 0x61 0X24; |
14 | Exit CFGUPDATE mode by sending either EXIT_CFG_UPDATE_REINIT (0x0091) or EXIT_CFG_UPDATE (0x0092) commands. | wr 0x00 0x91 0x00; or wr 0x00 0x92 0x00; |
15 | Confirm CFGUPDATE mode by polling OperationStatus() register until bit 2 is clear. May take up to 1 second. | rd 0x3B OperationStatus(); |
16 | If the device was previously SEALED, return to SEALED mode by sending the Control (0x0030) subcommand. | wr 0x00 0x30 0x00; |