Dear Sir
My customer want to use BQ76925 function.
I could not find what kind of data to do XOR with x8+ x2+ x + 1(100000111)
Does it XOR with data? or device + data ?
Arking
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dear Sir
My customer want to use BQ76925 function.
I could not find what kind of data to do XOR with x8+ x2+ x + 1(100000111)
Does it XOR with data? or device + data ?
Arking
Hi Arking,
When using the CRC every transaction will contain 3 bytes: (Address,R/W),(Data),(CRC). The CRC is calculated over the first 2 bytes in the transaction: (Address,R/W),(Data). For example, suppose you want to write the data 0x55 to register address 0x02. The 7-bit combined address is calculated as shown in Table 4 in the datasheet and is equal to 0x22 (010_0010). The R/W bit is '0' for a write and is added on the right-hand side of the combined address so that the transmitted address byte = 0x44 (0100_0100). The CRC is then calculated over 0x44,0x55 and is equal to 0xA3.
There are a number of techniques for computing the CRC. Here is some pseudo-code that shows one way of doing it:
char poly = 0x07 # 8-bit polynomial
char crc = 0x00 # Initialize 8-bit CRC
for each byte in message: # Loop over all bytes in the message
crc = crc xor byte
for index = 1 to 8: # Loop over all bits in the CRC
if crc > 127: # If msb is set, shift left and XOR with poly
crc = crc << 1
crc = crc xor poly
else: # Else just shift left
crc = crc << 1
Best Regards