Unsigned CRC32 check

Hi all!

been dealing for a couple of days with this and I’m pretty much stuck. Wrote a simple function on a Python script to interact with an electronic device, this device uses a CRC32 check as part of its serial communication protocol. My current Python function looks like this:

def calculate_crc(payload):
   crc = binascii.crc32(binascii.unhexlify(str(payload)))
   return hex(crc % (1<<32))

So for a desired payload I got the CRC32:

>>> calculate_crc('620004')
'0xb37f0245'

Which is OK as I tested against the device. Now, porting the code to Arduino, I hit a wall when trying to replicate this same behavior.

I’ve tried to use:

Without any luck, no matter what I do, I cannot replicate the same CRC32 I got from the Python script. Aside from that I receive different values, which leads me to think I’m not handling it very well.

The implementation hardware guide says:

CRC32: This is the big-endian 32 bit CRC or all payload bytes i.e. excluding size and CRC. The CRC32 is
implemented as per public domain ‘crc32.c’ (http://www.csbruce.com/software/crc32.c)

Can anyone help me point the right direction?

Thanks in advance

What about porting the code at the website you linked?

EDIT:
What Arduino board are you using? I do see that the static table in that code would take up half of the available RAM on an Uno.

Hi!
Porting the code was one of my ideas, but I'm not such a good programmer so I think I'll mess up all the code before getting it working :stuck_out_tongue:

I'm using an Arduino UNO, and yes, that static table is quite big for the UNO maybe.

What I think I'm missing here is the unhexlify from Python, which converts the 620004 HEX to BIN, then crc32 calculates its crc32.

masterl1nk:
Porting the code was one of my ideas, but I’m not such a good programmer so I think I’ll mess up all the code before getting it working :stuck_out_tongue:

Seems like a good learning opportunity. Get started on it and post here when you get stuck.