Hello,
I'm trying to get the RAM save/restore code for the BQ27426 working (in particular, I'm trying to store the State and Ra subclasses to nonvolatile memory, and then write them back to the device). I think I got the process working correctly, but I'm still not sure on how the checksum works.
The Technical Reference says BlockDataChecksum holds the LSB of the sum of the 32 bytes currently addressable from 0x40 to 0x5F, and that I should write the complement of the checksum (255 - (checksum & 0xFF)) after writing to transfer that data to RAM. There are examples in that document that show how to calculate the new checksum by reading the old one and reading that old data that is going to be replaced, but I'd like to avoid that, if at all possible. I'd also like to be able to check that the data that I've read is correct by calculating a checksum on my end.
I'm specially unsure as to how this all works because both the State and Ra subclasses are less than 32 bytes long (31 and 30, respectively). Should I add padding and write/read the whole 32 bytes? Do I need to wait for some time after setting the subclass and offset for the data to be readable and the checksum to be calculated, or can I start reading/writing right away? Right now I'm reading the 31 bytes of the State subclass immediately after setting the subclass and offset, calculating the checksum (by adding all of the bytes and then taking the LSB), and it doesn't match the value of BlockDataChecksum.
Thanks!