4

I have old serial communication protocol and having some trouble finding out about checksum algorithm that has been used. I've tried several CRC16 algorithms and none of them seem to work.

Tx message format looks like:

start(10B) + messageIndex(1B) + data(5-15B) + checksum(2B) + end(1B) 

Rx message has same format but only 1 data byte. Here are few examples provided (hash # added to separate the blocks; hexadecimal format):

Tx: 82 00 00 00 01 00 00 00 ff c1 # 48 # 56 57 50 41 54 5f 30 5f 31 3d 31 # 7f 12 # 83
Rx: 82 00 00 00 ff 00 00 00 01 01 # 48 # 4f # cc 68 # 83

Tx: 82 00 00 00 01 00 00 00 ff c1 # 49 # 56 57 50 41 4e 5f 30 5f 32 3d 49 55 30 30 30 # f5 16 # 83
Rx: 82 00 00 00 ff 00 00 00 01 01 # 49 # 4f # 5c 69 # 83

Tx: 82 00 00 00 01 00 00 00 ff c1 # 4a # 56 57 50 41 54 5f 30 5f 32 3d 31 # b8 1b # 83
Rx: 82 00 00 00 ff 00 00 00 01 01 # 4a # 4f # ac 69 # 83

Tx: 82 00 00 00 01 00 00 00 ff c1 # 4b # 56 57 41 4b 54 50 4e 5f 30 3d 32 # 60 6f # 83
Rx: 82 00 00 00 ff 00 00 00 01 01 # 4b # 4f # 3c 68 # 83

Tx: 82 00 00 00 01 00 00 00 ff c1 # 4c # 56 57 50 41 4e 5f 31 5f 31 3d 49 4c 30 30 30 # 6a ec # 83
Rx: 82 00 00 00 ff 00 00 00 01 01 # 4c # 4f # 0c 6a # 83

If necessary, I can provide more data. Any help or hint would be appreciated ;)

Best regards, Zlatko

EDIT The correct algorithm is regular CRC16 (0x8005 polynom). Thanks booto for correct answer.

1 Answer 1

12

It's a big-endian CRC16 (polynomial 0x8005) of the data from the byte following the 0x82 up to and including the byte before the CRC.

For example, for your last RX frame:

82 00 00 00 ff 00 00 00 01 01 4c 4f 0c 6a 83

The CRC16 of {0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x01,0x01,0x4c,0x4f} is 0x0c6a.

To find out this CRC algorithm, I assumed that 0x82 was a 'Start-of-Frame' marker and 0x83 was an 'End-of-Frame' marker. Then, I plugged the remaining data (sans crc field) into this on-line CRC calculation application and the emitted CRC16 looked correct.

I, then, checked a few of the other frames you supplied and verified the CRC calculation with other sources.

And, voila...

3
  • Out of interest, how did you work that out? Aug 12, 2015 at 7:44
  • 5
    I assumed 0x82 was a Start-of-Frame marker and 0x83 was an End-of-Frame marker. I plugged the remaining data (sans crc field) into lammertbies.nl/comm/info/crc-calculation.html and the emitted CRC16 looked correct. I then checked a few of the other frames you supplied and verified the crc calculation with other sources.
    – booto
    Aug 12, 2015 at 8:23
  • 1
    I have tried the algorithm on few more examples that I have not posted and it does work.
    – zlajoan
    Aug 12, 2015 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.