cancel
Showing results for 
Search instead for 
Did you mean: 

CRC calculation problem

matic
Associate III
Posted on December 16, 2015 at 15:40

Hi.

I'm trying to calculate CRC on STM32F303 using CRC peripheral. I check the correctness of calculation with this on-line application:

https://ghsi.de/CRC/

 But I have problems, when I want to calculate CRC above more than 32 bits.

If I write to CRC->DR register 32 bits it returns the same as on-line app.

For example:

- Init value: 0x00000000

- Polynomial: 0x97

- Input data: 0xA5A5A5A5

Here I get CRC value of 0x5A. And the same result I get with on-line app.

But if I want to calculate CRC above 40 bits, I don't get the same value anymore.

For example:

- Init value: 0x00000000

- Polynomial: 0x97

- Input data: 0xA5A5A5A5CC

Write CRC->DR = 0xA5A5A5A5  returns 0x5A.  Above that I write CRC->DR = 0xCC. And I get 0xFF.

Then I use on-line app. And I write input data as: 0xA5A5A5A5CC. It returns 0x44, which is not the same as uC returns. Obviously, I'm doing something wrong.

I have set REV_OUT and REV_IN in CR register to 0.

Do you have any advice? Thanks

#worst-forum-software-ever
16 REPLIES 16
Posted on December 16, 2015 at 17:34

How does it know you're writing an 8-bit value unless you cast it?

*((uint8_t *)&CRC->DR) = 0xCC;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on December 16, 2015 at 22:15

Thanks Clive, I will try that.

matic
Associate III
Posted on December 17, 2015 at 15:36

It works. Thanks.

matic
Associate III
Posted on January 05, 2016 at 14:32

Hi.

Now I have another problem. I am working on a BiSS protocol and want to implement CRC with standard 0x43 polynomial. I want to use hardware CRC module.

I can't get the correct values. I get correct result only if I set CRC_POL register to 0x3 (omitted upper 1 in 0b1000011 polynomial) and with very small input values (5-bit value max.) to DR register.

Do you have any suggestion what is going wrong here? Thank you in advance

Posted on January 05, 2016 at 14:43

> Now I have another problem. I am working on a BiSS protocol and want to implement CRC with standard 0x43 polynomial.

Can you give us a couple of correct examples?

JW
matic
Associate III
Posted on January 05, 2016 at 15:37

Ok.

First, I am testing with this software:

https://ghsi.de/CRC/index.php?Polynom=1000011&Message=aaaaaaaa

(polynomial should be set to 1000011)

One example which works can be found in this

http://www.google.si/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwi62YTn7pLKAhWFXSwKHSxKBAEQFggdMAA&url=http://www.biss-interface.com/files/BiSS_AN6_appnote_A2en.pdf&usg=AFQjCNEJusuxCBMHOOS2AcZbWgiH9b85Wg&sig2=7gMxupka3PDQrCvMTnwvzw

.

On the second page, there is an example with 0x43 polynomial and 0b11 input value.

If I put this combination to mentioned software, it turns value 0x5. (Note: The input value should be written as 0x3)

Now, if I set polynomial in POL register of a uC to 0x3 and write 0x3 to DR register as input value (same input as before with software), I get 0x5. So, this is true. Althoug I don't know why it works with 0x3 polynomial and not with 0x43. But in this manner (with 0x3 POL) it works for every value which is smaller then 0b100000. So, it works for 0b11111 and smaller inputs.

This is a little strange I think. CRC should be computable over unlimited input value, regardless to polynomial.

Thank you for yor help.

Posted on January 05, 2016 at 17:15

Do you have any suggestion what is going wrong here?

Yes, the HW really isn't built do to any other than 8, 16 or 32-bit operations.

Do the computation in SW

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on January 05, 2016 at 17:30

But why it works with numbers smaller than 0x20?

Posted on January 05, 2016 at 18:39

My previous OT post is of the same ''no title'' type... if you switch from Flat to Threaded view of the thread, you'll see that your post was ''Started'', as if you'd start a new thread (or subthread?) but that fails somehow, that's why it fails to display as standalona, has ''no title'', does not reflect properly poster and timestamp in the threads list.