0

I have to implement a communication protocol which runs via I2C and is used for a board2board communication of two distributed microcontrollers. To ensure the data integrity, I want to add to the communication protocol a checksum and thought something like CRC-8 or CRC-16 should fit, but unfortunately I have no glue, which criteria I should use to determine the best algorithm and in the next step, the best setting (like the value of the polynomial in case of CRC).

My protocol is quite simple, only one 32-bit read and one 32-bit write command are defined:

  • I2C Master Read Command:

    • Request (I2C WR): 2 bytes memory index + checksum
    • Response (I2C RD): 4 bytes data + checksum
  • I2C Master Write Command:

    • Request (I2C WR): 2 bytes memory index + 4 bytes data + checksum

I read on a forum post, that the CRC length depends on the data size which should be verified, so CRC-8 can sufficiently verify 28 % 8 (=32bit) and 216 % 8 (=8KiB) data for CRC-16. If that`s true, CRC-8 should be enough, but I don't know if this statement is correct...

Can someone please help me, how I can determine the best checksum algorithm for my protocol?

user9564464
  • 173
  • 2
  • 16
  • That should be `(2^8)/8 = 32 bits` and `(2^16)/8 = 8192 bits`. I'm not sure where those formulas are from. Take a look at [crc zoo](https://users.ece.cmu.edu/~koopman/crc/crc8.html). The 8 bit crc's where the second number in the list {...} >= 32 have Hamming distance == 4 for that bit length, such as (0xbf , 0x17f) ... {119,119,...} which has hamming distance 3 and 4 at 119 data bits (total message length would be 119 data bits + 8 crc bits = 127 bits). The 0xbf is (0x17f-1)/2, I don't know why the first entry in the tables are (crcpoly-1)/2, since the second entry is crcpoly. – rcgldr May 22 '19 at 23:24
  • To explain why 0x17f has Hamming distance == 4, 0x17f => (x^8 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) = (x^7 + x^6 + x^6 + x^2 x + 1 )(x + 1). For a 127 bit message (119 data bits, 8 crc bits), the (x^7 + x^6 + x^6 + x^2 x + 1 ) factor detects 2 bit errors (HD == 3), and the (x+1) factor detects parity errors (any odd number of errors), so the net detection is 3 bit errors (HD == 4) for any error pattern of 3 bit errors. Higher numbers of bits in error have about a 1/256 chance of not being detected. – rcgldr May 22 '19 at 23:56

1 Answers1

0

According to this table Best CRC polynomial a best fit CRC depends on the data size and hamming distance. More hamming distance is deep, less data is handling by CRC. You will have to predict (as more as possible) if HD is included in range.

But , i don't understand your statement : x power y mod z = x^y -(x^y/z * z) = 2^8 - (2^8/8 *8) = 0

nissim abehcera
  • 821
  • 6
  • 7