From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CRC-16 with 0x8005 polynomial

Solved!
Go to solution

I am using a CRC-16 VI from an NI community page that uses 0xA001, which is the reverse of the polynomial I want to use, 0x8005. For example, with one byte data 0xD6, the CRC-16 with 0xA001 is 0xDE3E, it should be 0x9E81 using polynomial 0x8005. Simply changing the polynomial does not seem to give the right result. I have an image attached. Is there something I should "flip", or "reverse" to in order to use the polynomial I want and get the right answer?

 

crc16.PNG

0 Kudos
Message 1 of 22
(9,060 Views)

Unfortunately, there are many ways to do a CRC.  Where are you getting the data point for your example?  Does that source have some source code (usually in C) we can look at?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 22
(9,047 Views)

The data is entered in the front panel. This VI can be used as a sub-VI for other VIs. There is no C-code, just the VI.

0 Kudos
Message 3 of 22
(9,006 Views)

The input control is an array of U8.

 

If your data source is little endian, then the bytes might need to be swapped after converting the array to unsigned word integer. LabVIEW is big endian.

 

http://zone.ni.com/reference/en-XX/help/371361H-01/glang/swap_bytes/

 

swap bytes.jpg


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 4 of 22
(8,988 Views)

@swbpnole wrote:

The data is entered in the front panel. This VI can be used as a sub-VI for other VIs. There is no C-code, just the VI.


What I was asking is where your "0x9E81" came from.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 22
(8,973 Views)

I used an online CRC-16 site to check the output of the VI against. This one:

 

http://www.lammertbies.nl/comm/info/crc-calculation.html

0 Kudos
Message 6 of 22
(8,967 Views)

After downloading the library from that site, I see that the CRC-16 with a 0x8005 is doing things a little differently than a "normal" CRC.  I'll see if I can get some time at lunch to mess around with it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 22
(8,956 Views)

I am not using the library from that site. I was using the site's online CRC calculation to check the output of the VI above against the site's normal CRC-16. In the end, I need the VI above to compute CRC-16 with polynomial 0x8005...

0 Kudos
Message 8 of 22
(8,951 Views)
I get the 0x9e81 result using a 0x8005 polynomial with the following: "Reverse Data Bits" Use rotate right with carry which you do correctly. Use an "Initial Value" of 0x0000 not 0xFFFF. Finally do a "Bit Reversal" of the CRC.
Message 9 of 22
(8,936 Views)

@jamiva wrote:
Finally do a "Bit Reversal" of the CRC.

I did not think about reversing the bits in the final CRC.  It is kind of a pain, but it did work.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 22
(8,920 Views)