Bq27220 checksum calculation:
I am trying to set design capacity for BQ27220 from the default 3000mAH to 13200 mAH using the external MCU to write I2C command to update the RAM area of BQ27220. But when I follow the 16 steps described in TRM in Chapter 6 of bq27220 Technical Reference Manual (sluubd4.pdf) www.ti.com/.../sluubd4. However, the readback data is wrong if I follow the steps there.
Then I found the forum discussion here: Bq27220: Can not update data memory parameter e2e.ti.com/.../585243
and I follow the steps as described below:
"UPDATE : Got it working ! There is an error in the example, after the step 8, you need to repeat the steps 5 and 6 else there is an offset of 0x0200 in the parameter address. When you read dataLen the address pointer change and you are not anymore at the right position. The TI documentation for writing the data memory is very poor, it is difficult to understand how it is working because the paragraph "3.1 Accessing the Data Memory" is wrong, it is just a copy/paste from others battery fuel gauge..."
This time, i got it working to show the correct design capacity as 13200mAH. I hope TI can improve the bq27220 Technical Reference Manual so that to show the correct steps in the example.
Another issue I faced is the checksum calculation:
I am a bit confuse with the checksum calculation. So far, i found two ways of calculating the checksum:
Method 1) Checksum is (255 – x) where x is the 8-bit summation of the BlockData() (0x40 to 0x5F) on a byte-by-byte
basis.
Method 2) 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);
I used both method to calculate the checksum, but i dont understand why i get the different checksum by using those two methods. I am in doubt whether they should end up with the same checksum. Can any expert confirm on this? Let me show you my calculation:
Method 1:
Here is the blockData (0x40 to 0x5F) : 0b b8 03 84 0e 74 00 64 0e 9f 00 95 03 63 0f be 01 3c 09 00 00 0b d7 01 0d 39 01 0d ad 01 10 4d
I get checksum = 0xD2 and the checksum read at register 0x60 is 0xA1. I don't understand how this checksum is calculated.
Method 2:
I use the method 2 to calculate the checksum, the result match 0xA1. [ temp= =MOD((255-161-11-184),256) = 155, new checksum=255 - [MOD((155+51+144),256)]= 255 -94 =161 (0xA1) which match what I read from the register 0x60.
My question is why the checksum calculation using the method 1 come out with wrong checksum? Did I actually read the wrong register again???
best regards,
kpk