09-01-2023 09:33 AM
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!
Solved! Go to Solution.
09-01-2023 09:47 AM
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...
09-01-2023 12:17 PM - edited 09-01-2023 12:20 PM
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.
(Edit: I first put up the wrong snippet, sorry.)
I backsaved the code to 2019 for the attachment.
Hope this helps!
Dave
09-08-2023 04:59 AM
Thanks Dave, this is exactly what I was trying to do!
02-09-2024 02:01 PM
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!!
02-09-2024 02:54 PM
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