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.

Example Code

16-bit CRC CCITT

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example generates a 16-bit error checking code that will efficiently confirm the correct retrieval of information.

 

Description

This code completes the complex calculation of taking the quotient of the input message and a known X value and passing that value as a Cyclic Redundancy Check (CRC). The message as well as the CRC are sent to their destination where the receiver will perform the same division this time with the message and the CRC. If there are no errors in the message, then the destination should get the X value as the quotient. In both of these calculations, any remainder generated is discarded.

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.
For CRC_CCITT: Polynomial Register = X16+ X12 + X5 +1 (0x1021)
Seed Register: 0xFFFF

 

 

Requirements

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code

1. Open the VI "Cyclic Redundancy Check (16 bits)_LV2012_NI Verified"

2. Enter the message to be coded in the String
3. Run the VI
4. Check the code in CRC-CCITT correspondent to your message

 

 

Additional Information or References

 

 

CRC-16 General Circuit. (Reference: http://www.cypress.com/file/127146/download)

 
cyclic prefix calculation.PNG

 

 Block Diagram

BD.PNG

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

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

Comments
lecher22
Member
Member
on

help

jlkjdflsfj

BetaCommunityCo
Member
Member
on

incorrect CRC

http://www.joegeluso.com/software/articles/ccitt.htm

according to the link above you should get a CRC of E5CC for a string of 123456789 using the 1021 poly with initial value of FFFF

Hagar
Member
Member
on

???? That is exactly the value this VI is returning for those conditions... Why are you saying "incorrect CRC" ? Am I missing something here?

CP115
Member
Member
on

I agree that something appears to be wrong with this code. The VI outputs the CRC-CCITT equal to that produced when using an initial value of 0x1D0F, not 0xFFFF (with poly 0x1021).

 

Cross check I/O with the site: https://www.lammertbies.nl/comm/info/crc-calculation.html

 

For an ASCII string 123456789, the CRC with 0xFFFF should be 29B1. This code outputs E5CC which is associated with 0x1D0F. This is incorrect. Without doing a deep dive into this code I don't know what is wrong exactly (even though it appears to use 0xFFFF as an initial condition). Has anyone solved this problem?

MrJackHamilton
Member
Member
on
I would also offer, the CRC should take a string input, calculate the CRC and ADD it to the end of the string. I am not sure why this code is lacking this part. What sense is a CRC function if it does not do this. Yes, it's 'easy' but a more useful functional post is more appreciated.
lapingéant
Member
Member
on

The error is related to the question of "augmended" zero bits at the end of the message.

More information here : http://srecord.sourceforge.net/crc16-ccitt.html