Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate CRC 16 with polynomial x16 + x12 + x5 + 1

I am trying to interface with some system and in their specs they require to calculate CRC 16 for serial communication. Here is an extract from documentation

"16 bit CCITT CRC of the message utilizing the standard polynomial, X16 +X12 +X5 +1. Seed values are always 0 (zero)"

First of all I only found 2-3 samples of C# code of how to do it and none of the seem to give me the correct value. I tried this one http://www.sanity-free.com/133/crc_16_ccitt_in_csharp.html, but I am not sure what to set for initial value. I tried zeros and still doesn't work.

Data I am testing it with is:

0x00 0x09 0x10 0x01 0x01 0x7C 0xF4 0xB8 0x00, 

the CRC value I get is

0xF2 0x24, 

however their system says it should be

0xC0 0x2F

My understanding is that polynomial x16 + x12 + x5 + 1 = 0x11021, however even when I use this one in the code it still gives me wrong answer. What am I doing wrong?

like image 569
fenix2222 Avatar asked Mar 06 '13 12:03

fenix2222


People also ask

How do you find the CRC of a polynomial?

A CRC is pretty simple; you take a polynomial represented as bits and the data, and divide the polynomial into the data (or you represent the data as a polynomial and do the same thing). The remainder, which is between 0 and the polynomial is the CRC.

How is CRC 16 implemented?

Step-01: Calculation Of CRC At Sender Side-A string of n 0's is appended to the data unit to be transmitted. Here, n is one less than the number of bits in CRC generator. Binary division is performed of the resultant string with the CRC generator. After division, the remainder so obtained is called as CRC.

What is the CRC polynomial?

A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to digital data. Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents.

What is CRC Ccitt 16-bit?

The CRC- 16 bits code computes a 16-bit cyclical redundancy check (CRC) algorithm on an input serial data stream. The polynomial can be defined to implement CRC functions, such as the CRC-16 or CCITT algorithm. A seed value can be specified to initialize the starting data value.


1 Answers

I figured it out. I had to use CRC16-CCITT Kermit inmplementation. I think their documentation needs to be updated as it uses a different polynomial.

http://www.sanity-free.com/147/standard_crc16_and_crc16_kermit_implementation_in_csharp.html

like image 103
fenix2222 Avatar answered Sep 23 '22 08:09

fenix2222