Tool/software:
Hi,
I'm trying to implement an integrity check based on the following description in the TRM to verify if the register value (e.g., CC_GAIN) I have read is what the AFE actually sent.
The following snapshots show the sequence of communication based on my current implementation which leads to a failure in checksum match. Could you please point me to where I'm missing?
1. Asks for CC_GAIN(0x91A8)
2. Reads 4-byte data
3. Reads the checksum at 0x60
And the following is the function which calculates the checksum based on the description "The checksum is calculated over 0x3E, 0x3F, and the buffer data, it does not include the checksum or length in 0x60 and 0x61." highlighted above in the TRM snapshot. (The parameter `cmd` is what's written to 0x3E and 0x3F.)
uint8_t checksum_with_cmd(const uint16_t cmd, const uint8_t * const p_buf, const uint8_t len) { uint8_t i; uint8_t checksum = 0; checksum += (uint8_t)(cmd & 0xff) ; checksum += (uint8_t)(cmd >> 8 & 0xff); for (i = 0; i < len; i++) { checksum += p_buf[i]; } checksum = 0xff & ~checksum; return checksum; }
In this example, the AFE returns 0x2F, and my `checksum_with_cmd()` function returns 0x99 whose calculation was performed over (0xA8, 0x91, 0x52, 0x27, 0x74, 0x40).
Thank you,
Kyungjae Lee