LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing CRC checksum CRC-8 with 0xFF initialization - Sensirion SHT85

Solved!
Go to solution

Relatively new to using I2C communications and trying to get my head around Checksum Calculations and wondering if anyone with previous knowledge can help here? I'm using a Sensirion SHT85 Temperature and Humidity sensor and can confirm communication with the device via I2C. I receive 2 8-bit messages back from the instrument followed by an 8-bit checksum. I'm looking to build a piece of code alongside the data collection that confirms the correct checksum to confirm the data transfer. The CRC algorithm is a CRC-8 with an initialisation 0xFF. Does anyone have something like this pre existing? Is it easy enough to create an algorithm in the code or easier to use a look up table?

 

Many thanks!

0 Kudos
Message 1 of 6
(3,101 Views)

Searching CRC-8 in the forum listed a bunch of results - https://forums.ni.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&filter...

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 6
(3,094 Views)
Solution
Accepted by topic author owhiteside

I pulled out a CRC-8 VI I had done previously, but it uses a different poly and seed, so I substituted the ones you referenced (0x31, 0xFF initial, no reflectance).  I can't immediately find a well-known name for this variant, but whatever.  Code for doing these brute-force is pretty simple.  If you take the time to develop a lookup table constant, you can eliminate the shifting/looping on each input byte.  See below.

CRC8.png

 (Edit: I first put up the wrong snippet, sorry.)

 

I backsaved the code to 2019 for the attachment.

 

Hope this helps!

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 3 of 6
(3,056 Views)

Thanks Dave, this is exactly what I was trying to do! 

0 Kudos
Message 4 of 6
(2,986 Views)

Thanks for your input! i had been searching these forums and found other options and was thinking, there should be a solution that has the Initial Value and Polynomial value clearly shown, thereby, enabling it to handle any variation. Thanks again!!

0 Kudos
Message 5 of 6
(2,249 Views)

Sometime after I posted to this thread last September, I went on a search for somebody... somewhere... who would surely have created an all-things-CRC VI library.  I came up short on that search.  Since then, I created my best attempt at a project reuse library that would support 8/16/32 and (yes, Virginia, there are) 64-bit CRC computations as a single malleable VI, with options to use the shift-test-XOR (brute force, as below), or specify a one-time-build of a lookup table.

 

It's basically ready to go, as fully documented as I can make it, and includes lists of all the "well-known" named CRC implementations (they are myriad!) with their polynomials, initial values, and input/output reflections.  The library also includes links to some online CRC reference and computation websites (hopefully the more authoritative/reputable ones, they are also myriad).

 

Though this sounds more complex than the one-off LabVIEW solutions for "hey, how can LV do this <CRC-xxx> I need?" I see sprinkled throughout the forums, it really is a tiny library and lends itself to (hopefully) universal use.

 

The basic VIM will compute 8/16/32/64 based on poly/init integer size wired, and will also adapt to string, byte array, or file path input (for CRC computations of file content).  If allowed, it'll one-time-call a lookup table builder (also malleable) so if you're going to be doing a LOT of CRC calls, it may be more efficient.  (Disclaimer: performance testing harness has not been created so I haven't evaluated this at this time).

 

Built in LV 2023.  I'm thinking this might be worthy of tossing onto the LAVA Code Repository (uncertified) as a first stop to future glory.  Look for it there, shortly.

 

Dave

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 6 of 6
(2,240 Views)