Dear Battery Team,
I have some questions to the reading out of the correction factors.
According to the datasheet the factors are stored as 5 or 6 bit values in 2’s complement.
As given in table 2 and table 3 in the datasheet the MSBs and LSBs are simply shifted and arranged.
The sample code in sluc581 shows the following:
// Get the 2 msb for offset and 1 msb for gain correction of VREF
if (i2c_read(VREF_CAL_EXT, &i2c_read_struct)) error_trap();
// Shift in msb and sign extend
offset_corr[0] |= (((i2c_read_struct.data & 0x06) << 3) ^ 0x20) - 0x20;
gain_corr[0] |= (((i2c_read_struct.data & 0x01) << 4) ^ 0x10) - 0x10;
The shift seems correct but the data is also XORed with the MSB and the MSB is subtracted at the end.
To me it seems, that this has no effect.
Example:
Data: 00001
XOR with 10000 gives 10001
Subtraction by 10000 gives 00001 (the same as the input data).
Maybe this is the code of a former chip.
I would keep to the datasheet which results in a reduced code for the reading of the correction factors.
To be sure – could you clarify that?
Best wishes,
Olrik