Part Number:BQ27421-G1
帮忙看一下代码和日志写的有没有问题,是按照文档bq27421-Technical Reference里面的3.1发送的命令,是文档3.1的命令顺序.
电量计代码和日志.txt
unsigned int battery_ModifyDesignCapacity(void) { uint8_t data[4]={0}; uint8_t dataBuf[2]={0}; uint8_t addr = 0x55; unsigned int volt = 0; uint8_t ret = 0; uint8_t OLD_Csum = 0; uint8_t OLD_DesCap_MSB = 0; uint8_t OLD_DesCap_LSB = 0; uint8_t temp = 0; uint8_t NEW_Csum = 0; DBG_STR("----------------ModifyDesignCapacity---------------"); data[0] = 0x06;//flags ret = GPIO_I2CWriteByte(addr, data[0], 0); ret = GPIO_I2CReadNByte(addr, dataBuf, 2, 0); data[0] = 0x00; data[1] = 0x00; data[2] = 0x80; ret = GPIO_I2CWriteNByte(addr, dataBuf, 3, 0); data[0] = 0x00; data[1] = 0x00; data[2] = 0x80; ret = GPIO_I2CWriteNByte(addr, dataBuf, 3, 0); data[0] = 0x00; data[1] = 0x13; data[2] = 0x00; ret = GPIO_I2CWriteNByte(addr, dataBuf, 3, 0); mdelay(2000); data[0] = 0x06;//flags ret = GPIO_I2CWriteByte(addr, data[0], 0); ret = GPIO_I2CReadNByte(addr, dataBuf, 2, 0); data[0] = 0x61; data[1] = 0x00; ret = GPIO_I2CWriteNByte(addr, dataBuf, 2, 0); data[0] = 0x3E; data[1] = 0x52; ret = GPIO_I2CWriteNByte(addr, dataBuf, 2, 0); data[0] = 0x3F; data[1] = 0x00; ret = GPIO_I2CWriteNByte(addr, dataBuf, 2, 0); data[0] = 0x60;//OLD_Csum ret = GPIO_I2CWriteByte(addr, data[0], 0); ret = GPIO_I2CReadNByte(addr, dataBuf, 1, 0); //DBG_HEX("OLD_Csum(60):", dataBuf, 2); OLD_Csum = dataBuf[0]; DBG_STR("OLD_Csum=%x",OLD_Csum); mdelay(100); data[0] = 0x4A;//OLD_DesCap_MSB ret = GPIO_I2CWriteByte(addr, data[0], 0); ret = GPIO_I2CReadNByte(addr, dataBuf, 1, 0); OLD_DesCap_MSB = dataBuf[0]; DBG_STR("OLD_DesCap_MSB=%x",dataBuf[0]); mdelay(100); data[0] = 0x4B;//OLD_DesCap_MSB ret = GPIO_I2CWriteByte(addr, data[0], 0); ret = GPIO_I2CReadNByte(addr, dataBuf, 1, 0); OLD_DesCap_MSB = dataBuf[0]; DBG_STR("OLD_DesCap_LSB=%x",dataBuf[0]); data[0] = 0x4A; data[1] = 0x01; ret = GPIO_I2CWriteNByte(addr, dataBuf, 2, 0); //mdelay(100); data[0] = 0x4B; data[1] = 0x72; ret = GPIO_I2CWriteNByte(addr, dataBuf, 2, 0); temp = (255 - OLD_Csum- OLD_DesCap_MSB- OLD_DesCap_LSB)%256; NEW_Csum = 255 - (temp + 0x04 + 0xB0)%256; DBG_STR("temp=%d,NEW_Csum=%d",temp,NEW_Csum); data[0] = 0x60; data[1] = NEW_Csum; ret = GPIO_I2CWriteNByte(addr, dataBuf, 2, 0); data[0] = 0x00; data[1] = 0x42; data[2] = 0x00; ret = GPIO_I2CWriteNByte(addr, dataBuf, 3, 0); data[0] = 0x06;//flags ret = GPIO_I2CWriteByte(addr, data[0], 0); ret = GPIO_I2CReadNByte(addr, dataBuf, 2, 0); DBG_HEX("Flags(06):", dataBuf, 2); mdelay(100); data[0] = 0x00; data[1] = 0x20; data[2] = 0x00; ret = GPIO_I2CWriteNByte(addr, dataBuf, 3, 0); DBG_STR("----------------ModifyDesignCapacity---------end------"); } ----------------ModifyDesignCapacity--------------- Flags(06):a8 7f 1-Flags(06):a8 7f OLD_Csum=0 OLD_DesCap_MSB=0 OLD_DesCap_LSB=0 temp=255,NEW_Csum=76 Flags(06):a8 7f ----------------ModifyDesignCapacity---------end------
bq27421-Technical Reference.pdf
Star Xu:
您好,非常抱歉我没有设备可以运行代码。您运行代码以后有什么问题。