在实际使用的时候,电池的容量往往会和其默认容量不相等,需要修改其默认容量。修改过程比较繁琐,且掉电丢失,必须每次上电都初始化。它的参考手册,会提供一个写的例子,按照它的顺序,总是修改不成功。后来经过尝试终于摸索出来了。示例代码如下:
writebYTE(0x00, 0x14);
writebYTE(0x01, 0x04);
HAL_Delay(50);
writebYTE(0x00, 0x72);
writebYTE(0x01, 0x36);
HAL_Delay(50);
//复位
writebYTE(0x00, 0x41);
writebYTE(0x01, 0x00);
HAL_Delay(3500);
Old_DC_LSB = bq27220ReadOneByte(0x3c, &isReadOK);
Old_DC_MSB = bq27220ReadOneByte(0x3d, &isReadOK);
HAL_Delay(50);
//进入 FULL_ACCESS
writebYTE(0x00, 0xFF);
writebYTE(0x01, 0xFF);
HAL_Delay(50);
writebYTE(0x00, 0xFF);
writebYTE(0x01, 0xFF);
HAL_Delay(50);
//进入CGF_UPDATE
writebYTE(0x00, 0x90);
writebYTE(0x01, 0x00);
HAL_Delay(50);
{
//输入FCC地址
writebYTE(0x3E, 0x9d);
writebYTE(0x3F, 0x92);
HAL_Delay(50);
// //7 read old fcc
// Old_fcc_MSB = bq27220ReadOneByte(0x40);
// Old_fcc_LSB = bq27220ReadOneByte(0x41);
// HAL_Delay(10);
// //6 read Old_Chksum Data_len
// Old_Chksum = bq27220ReadOneByte(0x60); // 0x3d
// Data_len = bq27220ReadOneByte(0x61); // 0x24
// HAL_Delay(10);
Old_Chksum = 0x3d;
Old_fcc_MSB = 0xb8;
Old_fcc_LSB = 0x0b;
Data_len = 0x24;
designCap_L = (fcc >> 0) & 0x00ff;
designCap_H = (fcc >> 8) & 0x00ff;
Temp = mod(255 - Old_Chksum - Old_fcc_MSB - Old_fcc_LSB, 256);
New_Chksum = 255 - mod(Temp + designCap_L + designCap_H, 256);
//输入设计容量
writebYTE(0x40, designCap_H);
writebYTE(0x41, designCap_L);
HAL_Delay(50);
//输入校验和
writebYTE(0x60, New_Chksum);
HAL_Delay(50);
writebYTE(0x61, Data_len);
HAL_Delay(50);
}
HAL_Delay(500);
{
//输入设计容量地址
writebYTE(0x3E, 0x9f);
writebYTE(0x3F, 0x92);
HAL_Delay(50);
Old_Chksum = 0xa1;
Old_DC_MSB = 0xb8;
Old_DC_LSB = 0x0b;
Data_len = 0x24;
designCap_L = (dc >> 0) & 0x00ff;
designCap_H = (dc >> 8) & 0x00ff;
Temp = mod(255 - Old_Chksum - Old_DC_MSB - Old_DC_LSB, 256);
New_Chksum = 255 - mod(Temp + designCap_L + designCap_H, 256);
//输入设计容量
writebYTE(0x40, designCap_H);
writebYTE(0x41, designCap_L);
HAL_Delay(50);
//输入校验和
writebYTE(0x60, New_Chksum);
HAL_Delay(50);
writebYTE(0x61, Data_len);
HAL_Delay(50);
}
//退出CGF_UPDATE
writebYTE(0x00, 0x91);
writebYTE(0x01, 0x00);
HAL_Delay(50);
//进入seal
writebYTE(0x00, 0x30);
writebYTE(0x01, 0x00);
HAL_Delay(1000);
这段代码修改了两个值,设计容量和满充容量,它与给定的例子的不同点是在设置的过程中,没有读取Old_DC_MSB、Old_DC_LSB,在实际的使用过程中,只需要在调试的时候读取一次,后面就手动记下此值,在设置的时候就不读取了。实践证明可行。