Other Parts Discussed in Thread: EV2400, BQSTUDIO
Hello,
In my current design I'm using the fuel gauge BQ34210 and I am having issue in the software side when it comes to the configuration/update the design capacity. I believe the issue is in the way the checksum is calculated but I don't seem to find where the error is. Attached is a snipped of my code.
void BQ34210_updateDesignCapacity(int newDesignCapacity){ uint8_t MSB = 0; uint8_t LSB = 0; uint8_t CNFGUPDATE = 0; uint16_t value=0; uint16_t DesignCapacity=0; uint16_t Old_DC=0; uint8_t oldMACDataSum=0; uint8_t MACDataLen=0x24; uint8_t Temp; uint8_t New_Chksum; uint8_t Old_Chksum; uint8_t OLD_DC_MSB; uint8_t OLD_DC_LSB; uint8_t wait=0; uint8_t DeltaCHK=0; char adc_value[18]; // Unseal CyDelay(1); BQ34210_writeRegister(0x00,0x1404); CyDelay(1); BQ34210_writeRegister(0x00,0x7236); CyDelay(1); //Enter Config Update Mode BQ34210_writeRegister(0x00,0x0090); CyDelay(1); // BQ34210_writeRegister(0x00,0x7236); //while while((CNFGUPDATE!=1)||(wait<12)){ value=BQ34210_readRegister(0x3B); CNFGUPDATE = ((value>>8) & 0x04); CyDelay(10); wait++; CyDelay(10);//prevent from getting stuck in the loop } //Get access to Design Capacity BQ34210_writeByteRegister(0x3E,0x49); CyDelay(1); BQ34210_writeByteRegister(0x3F,0x93); //Read Old Chksum sum Old_Chksum=BQ34210_readByteRegister(0x60); CyDelay(1); //Read MAC Data lenght MACDataLen=BQ34210_readByteRegister(0x61); CyDelay(1); //Get access to Design Capacity BQ34210_writeRegister(0x3E,0x4993); CyDelay(1); //Get Design Capacity from MACData (0x40) OLD_DC_MSB=BQ34210_readByteRegister(0x40); CyDelay(1); //Read MAC Data lenght OLD_DC_LSB=BQ34210_readByteRegister(0x41); CyDelay(1); //Calculate new checksum (nned to figure out this) Temp=Old_Chksum; Temp=255-Temp; Old_DC= (OLD_DC_MSB + OLD_DC_LSB)%256; DeltaCHK=Old_DC-newDesignCapacity; Temp=abs(Temp-DeltaCHK); New_Chksum=255-Temp; // (255-Old_Chksum-OLD_DC_MSB-OLD_DC_LSB)%256; // New_Chksum=255-256%(Temp+0x04+0xB0); //Write new Design Capacity BQ34210_writeRegister(0x40,newDesignCapacity); CyDelay(1); //Write new checksum BQ34210_writeByteRegister(0x60,New_Chksum); CyDelay(1); //Write MAC Data len BQ34210_writeByteRegister(0x61,MACDataLen); CyDelay(80); //Get access to Design Capacity BQ34210_writeRegister(0x3E,0x4993); CyDelay(1); //Read the Design Capacity DesignCapacity= BQ34210_readRegister(0x40); CyDelay(1); }
From the datasheet:
Thank you,
Sam