Part Number:BQ27220
bq27220WriteOneByte(0x00, 0x41);
bq27220WriteOneByte(0x01, 0x00);
HAL_Delay(5000);
//1 读原来的设计容量
Old_DC_LSB = bq27220ReadOneByte(0x3c);
Old_DC_MSB = bq27220ReadOneByte(0x3d);
//
// data16 = (Old_DC_MSB << 8) | Old_DC_LSB;
//2 进入unseal
bq27220WriteOneByte(0x00, 0x14);
bq27220WriteOneByte(0x01, 0x04);
HAL_Delay(100);
bq27220WriteOneByte(0x00, 0x72);
bq27220WriteOneByte(0x01, 0x36);
HAL_Delay(100);
data_seal = bq27220ReadOneByte(0x3a);
//3 进入full access
bq27220WriteOneByte(0x00, 0xFF);
bq27220WriteOneByte(0x01, 0xFF);
HAL_Delay(100);
bq27220WriteOneByte(0x00, 0xFF);
bq27220WriteOneByte(0x01, 0xFF);
HAL_Delay(100);
data_seal = bq27220ReadOneByte(0x3a);
//4 enter cfg update mode
bq27220WriteOneByte(0x00, 0x90);
bq27220WriteOneByte(0x01, 0x00);
HAL_Delay(10);
do {
data_seal = bq27220ReadOneByte(0x3a);
data_update = bq27220ReadOneByte(0x3b);
HAL_Delay(100);
} while ((data_update & 0x04) == 0);
HAL_Delay(2000);
//5 get access to design capacity
bq27220WriteOneByte(0x3E, 0x9f);
bq27220WriteOneByte(0x3F, 0x92);
HAL_Delay(10);
//6 read Old_Chksum Data_len
Old_Chksum = bq27220ReadOneByte(0x60);
Data_len = bq27220ReadOneByte(0x61);
HAL_Delay(10);
//7 read old Design Capacity
Old_DC_MSB = bq27220ReadOneByte(0x40);
Old_DC_LSB = bq27220ReadOneByte(0x41);
HAL_Delay(10);
//8 write Design Capacity
bq27220WriteOneByte(0x40, 0x04);
bq27220WriteOneByte(0x41, 0xB0);
HAL_Delay(100);
//9写入校验值
uint8_t Temp = mod(255 – Old_Chksum – Old_DC_MSB – Old_DC_LSB, 256);
uint8_t New_Chksum = 255 – mod(Temp + 0x04 + 0XB0, 256);
bq27220WriteOneByte(0x60, New_Chksum);
HAL_Delay(100);
bq27220WriteOneByte(0x61, Data_len);
HAL_Delay(100);
//10退出 cfg_update
bq27220WriteOneByte(0x00, 0x91);
bq27220WriteOneByte(0x01, 0x00);
HAL_Delay(10);
do {
data8 = bq27220ReadOneByte(0x3b);
HAL_Delay(100);
} while ((data8 & 0x04) != 0);
HAL_Delay(2000);
//11返回seal
bq27220WriteOneByte(0x00, 0x30);
bq27220WriteOneByte(0x01, 0x00);
HAL_Delay(100);
data_seal = bq27220ReadOneByte(0x3a);
while (1) {
//12继续读取
Old_DC_LSB = bq27220ReadOneByte(0x3c);
Old_DC_MSB = bq27220ReadOneByte(0x3d);
}
这是我的相关代码,就是不能设置 Design Capacity,不知道有哪些问题
翻译
搜索
复制
Star Xu:
您好,建议您在尝试修改设计容量值之前尝试直接按照TRM 6.1 Data Memory Parameter Update Example步骤调试代码。确认是不是checksum错误导致不能修改参数。