Calculating CRC 8 for MLX90614

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi

I am experimenting with the Melexis MLX90614 and have come to a point where i
need to change the I2c Address , in order to accomplish this I need to send the following data than 1 CRC Byte of All
data
that has been sent .

Polynominal is : 100000111

0x00 - Address
0x2E - Address Register ( LSB Portion ONLY )
0x90 - LSB New Address Data
0x80 - MSB ( shuld be kept the same as it contains calibration values 0x80 is just an example )
0x?? - CRC 8 ( Result = 0x07 )

If i calculate the crc using the following websit it work fine ,but i wish to be able to calculate the
CRC Dynamically with flowcode .

Has anyone tried to accomplish something like this need some help :(

https://www.ghsi.de/CRC/index.php?Polyn ... e=002E9080

Thanks

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi

Just find a very simple way around this , if i send a data whit wrong CRC the sensor will not acknowledge the CRC byte
so what have done is a counter from 0 to 255 converted to hex and send as CRC byte , sort of Brut forcing the CRC
when the sensor acknowledge the CRC byte i know that the right CRC byte is reached and the new Address is
successfully written

It definitely takes more time than it should but it Works :D :D

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Benj »

Hi Alan,

That's a new CRC calculation on me. I've put together an example which seems to work, not promising this is the most elegant way of doing it or that it will work in all cases but seems to be working.
CRC_Calc.fcfx
(11.98 KiB) Downloaded 380 times

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

Will try it today and let you know

Thanks very much

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

Just gave a try to the fcfx file but the output dose not seem to match whit that of the website when i change the input data
This may be more tricky than it seems .

I found the following code for Arduino but dont now how to convert it from the following website I am also attaching
a very informative PDF File .

http://stackoverflow.com/questions/2055 ... o-mlx90614


byte c8( byte x ){
for( byte i = 8; i--; ) {
x = ( x << 1 ) ^ ( x & 128 ? 7 : 0 );
}
return x;
Attachments
20_crc-8_firmware_implementations.pdf
(58.9 KiB) Downloaded 297 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Benj »

This seems to work but again could be a fluke. Yep pretty sure it's not right as there is no summation of CRC from byte to byte.
CRC_Calc.fcfx
(10.59 KiB) Downloaded 278 times

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

Yes you are right it dose not work but it's OK , I managed with the Brut force method
it works quit well .

Thanks for your time

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Benj »

Hi Alan,

I think we are close, I just need to know how the CRC value is summed from byte to byte. Simply adding the output value together does not work. I'll have a quick hunt about and see if anything becomes clearer.

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

In the calculator website it explains what happens to the process

So the polynomial defines the sum 100000111 = P(x) = x8+ x2+ x1+ x0
and with this data as input : 002E9080 the following bindery is somehow calculated

00000000 is the initial CRC value (hide details)
Next hex digit [0]:
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Next hex digit [0]:
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Next hex digit [2]:
Shift in of [0] results in 00000000
Shift in of [0] results in 00000000
Shift in of [1] results in 00000111
Shift in of [0] results in 00001110
Next hex digit [E]:
Shift in of [1] results in 00011011
Shift in of [1] results in 00110001
Shift in of [1] results in 01100101
Shift in of [0] results in 11001010
Next hex digit [9]:
Shift in of [1] results in 10010100
Shift in of [0] results in 00101111
Shift in of [0] results in 01011110
Shift in of [1] results in 10111011
Next hex digit [0]:
Shift in of [0] results in 01110001
Shift in of [0] results in 11100010
Shift in of [0] results in 11000011
Shift in of [0] results in 10000001
Next hex digit [8]:
Shift in of [1] results in 00000010
Shift in of [0] results in 00000100
Shift in of [0] results in 00001000
Shift in of [0] results in 00010000
Next hex digit [0]:
Shift in of [0] results in 00100000
Shift in of [0] results in 01000000
Shift in of [0] results in 10000000
Shift in of [0] results in 00000111
$ 7 (hexadecimal)
% 00000111 (binary)
! 7 (decimal)


https://www.ghsi.de/CRC/indexDetails.ph ... e=002E9080

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

If you succeed in calculating the CRC and you can make the polynominal as an input variable
well that could be a nice new component for flowcode CRC8 calculator . :D :D

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Benj »

Hi Alan,

I've cracked it, confirmed with a few series of values.
CRC_Calc.fcfx
(9.96 KiB) Downloaded 351 times
A component would be great but I would need to figure out a few more bits regarding the variable polynomial.

Anyway this code seems to work and should allow your code to function without resorting to brute force.

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

Yes that works 100% well done , this will be a lot faster than the brut force method :D :D

Thanks again , and keep up the good work

User avatar
Alan_37
Posts: 179
Joined: Sun May 01, 2016 8:36 pm
Has thanked: 51 times
Been thanked: 54 times
Contact:

Re: Calculating CRC 8 for MLX90614

Post by Alan_37 »

Hi Ben

I have modified your code a bit now the Macro can take a Hex String as an input Example "01220A"
Hex values in the input String must have 2 characters if they are lower than 0x10 a 0 must be added at the beginning .

The Macro will .Return the result as decimal

Maybe this will make it a bit more easy to create a component :)

Thanks .
Attachments
CRC_Calc_v2.fcfx
(13.83 KiB) Downloaded 248 times

Post Reply