Example Code

Inline CRC Reference Library (CRC-32, CRC-16, and CRC-8)

Code and Documents

Attachment

Overview 

This Library implements the algorithms for CRC-8-CCITT, CRC-8-Maxim 1-Wire (DOW), CRC-16-CCITT (0xFFFF), CRC-16-CCITT (0x1D0F), CRC-16-CCITT xModem, and CRC-32 IEEE 802.3.

 

 

Description

 A cyclic redundancy check (CRC) is a hashing function used to detect unintentional changes to data.  A CRC is also often called a polynomial code checksum or a Frame Check Sequence (FCS)

The CRC-32 IEEE 802.3 algorithm uses a lookup table to calculate the CRC using the polynomial x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1.

 

The CRC-16-CCITT algorithms all implement a simplified LabVIEW version of the polynomial x16 + x12 + x5 + 1.  Each of the three versions use different initial values (0xFFF, 0x1D0F, and for xModem 0x0000).

 

The CRC-8-CCITT and CRC-8-Maxim algorithms use lookup tables to calculate the CRC for the polynomials x8 + x2 + x + 1 and x8 + x5 + x4 + 1 respectively.

 

 

Steps to Implement or Execute Code

1. Download the attached ogp file and double click on it. 

2. This will launch the VI Package Manager and direct you to the library installation

3. Proceed with the installation then once done click on Show in Palettes. this will highlight the VIs in the functions Palettes in LabVIEW

 

 

Requirements

LabVIEW 2009 (or compatible)

 

 

Additional Information or References

These functions can be used on Windows, Mac, Linux, RT, or FPGA (including inside of a Single Cycle Timed Loop) to calculate an inline CRC.

 

Each of these CRC algorithms have been validated using online CRC calculators, however, you should verify that these algorithms implement your exact CRC version (CRC-16-CCITT with intial value of 0xFFFF vs initial value of 0x1D0F) and that you receive the CRC value that is expected by your device or software.

 

This code is attached both as a zip file and a VI Package.  The Zip file allows you to easily unzip and use this library on any platform.

 

The VI package (niaes_lib_inline_crc-1.0.0-6.ogp) is intended for use with VI Package Manager™ (VIPM). VI Package Manager is an installer for LabVIEW VIs and toolkits. It places VIs directly into the palettes, allows you to install VIs into multiple LabVIEW versions, and ensures that any dependency VIs and toolkits (provided in other VI packages) are also installed. VI Package Manager is a product and trademark of JKI Software.

 

vipm.PNG

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Joji
NI Employee (retired)
on

Great Tool!  I am a novice when it comes to CRC.  How would you apply this to a TCP/IP frame or message. If you were sending 8bit packets. Do you apply the CRC and then send the 8bit packet and the 8bit CRC and the on the reciever side run the inline CRC again and verify that the two CRCs match?

Also, what is the Reset function for?

Joji
erchaj
Member
Member
on

Thanks.

josborne
Active Participant
Active Participant
on

Thanks for the code.  But I am having some trouble applying it in my application.  Here is my post on the discussion forum.  I think I am doing something wrong.  Any tips are appreciated!!

http://www.medicollector.com
josborne
Active Participant
Active Participant
on

Just wanted to update my own post.  I got the code to work.  As it turns out, I was feeding bytes into the code in the reverse direction.  I just needed to reverse all the bits before sending to this subVI.  Now it works!

http://www.medicollector.com
Martin_W
Member
Member
on

Hi, just wondering if the CRC 8 can be enhance with:

CRC-8 (SAE-J1850)

-8 + x4 + x3 + x2 + 1

with FF as start

thanks a lot !

Martin

x

Martin_W
Member
Member
on

and:

0A 00 00 gives CRC8 = 01

05 00 00 gives CRC8 = 87

小鹰fighting
Member
Member
on

谢谢分享!

RyanCheng
Member
Member
on

Thank you for your kindly share, it's very helpful!

TestNinja
Member
Member
on

How do you perform a CRC-8-CCITT in reverse?

AmitShachaf
Member
Member
on

Hi Jonathan,

I have look into the implementation and it is using the LUT implementation of the CRC code. The code looks very good. Most efficient way on window or RT.

I need to implement now a CRC on FPGA. The LUT array is using more memory then direct calculation of the CRC algorithm.

Do you have by any chance a code that implement the calculation of the CRC in a bit stream fashion?

Thanks - Amit,

Amit Shachaf
AmitShachaf
Member
Member
on

Hi John,

I need to implement CRC 5 algorithm. How do I modify the VIs to implement CRC-5?

Thanks - Amit,

Amit Shachaf
hjais
Member
Member
on

I tried calculating CRC 32 and the CRC returned was different as what is returned using http://www.lammertbies.nl/comm/info/crc-calculation.html.

crossrulz
Knight of NI Knight of NI
Knight of NI
on

My IT is blocking that site.  But make sure the polynomial is the same.  This implementation is very specific to a certain polynomial.


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
bmishoe
Active Participant
Active Participant
on

Is there a usage guide for this utility that I'm missing?  The 'data' input is obvious but what do I connect to the 'CRC in' input or the Reset input?  I looked at some other user's code and it appeared that the CRC in input in their case was a menu selection of what CRC algorithm they wanted to implement, but that's not what shows up for me when I right click to create a constant (not to mention, in my case I'm using CRC-32 which - according to the description above - should only apply to the 802.3 standard, so I'm not sure why this input exists for this SubVI).  Thanks for any help...

bmishoe
Active Participant
Active Participant
on

nevermind - I see now that the zip file includes an example.  I had downloaded the VIPM version, which I don't believe contains any examples...thanks anyway.

labview183
Member
Member
on

thank you!

Jamminator
Member
Member
on

Does anyone know how I can use this code to do a DARC-8 polynomial?