Dear forum users,
I have some trouble writing to the data flash of the BQ35100.
Since writing to the config A register works, I'm trying to use the same order and code of Config A to write the battery capacity.
This is the code i'm using to set the battery capacity:
uint8_t writeToDataFlash(uint16_t writeRegister, uint16_t data, uint8_t dataSize ) { if ( !dataSize ) return FAIL; uint8_t check[2] = { 0 }; uint16_t checkBuffer = 0; uint8_t pData[4] = { 0 }; pData[0] = writeRegister; pData[1] = writeRegister >> 8; pData[2] = data >> 8; pData[3] = data; if ( I2cWriteBuffer( &I2c, c_BQ35100I2CAddr, c_ManufacturerAccessControlAddr, pData, 2 + dataSize ) == FAIL ) { printf( llerror, "writetodataflash: Write register + data failed" ); return FAIL; } DelayMs( 100 ); //calculate checksum and write to MacDataSum + MacDataLen for ( uint8_t i = 0; i <= 2+dataSize; i++ ) { checkBuffer += pData[i]; } check[0] = ~checkBuffer; check[2] = 4 + dataSize; //The next write function auto increments! I2cWriteBuffer( &I2c, c_BQ35100I2CAddr, c_ManufacturerAccessControlDataSumAddr, check, 2); DelayMs( 100 ); return SUCCESS; }
The data I want to send is the capacity of 17Ah (0x4268) to register 0x41FE:
writeToDataFlash(0x41fe, 0x4268, 2);
Reading the capacity always gives the default value, which is 2200mAh.
What am I doing wrong?
Thanks for helping me out!
Greets Jorg