Page 1 of 1

Calculating CRC 8 for MLX90614

Posted: Sat Jan 28, 2017 2:28 pm
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

Re: Calculating CRC 8 for MLX90614

Posted: Mon Jan 30, 2017 11:08 am
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

Re: Calculating CRC 8 for MLX90614

Posted: Mon Jan 30, 2017 12:38 pm
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 388 times

Re: Calculating CRC 8 for MLX90614

Posted: Mon Jan 30, 2017 2:10 pm
by Alan_37
Hi Ben

Will try it today and let you know

Thanks very much

Re: Calculating CRC 8 for MLX90614

Posted: Mon Jan 30, 2017 3:13 pm
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;

Re: Calculating CRC 8 for MLX90614

Posted: Mon Jan 30, 2017 4:47 pm
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 287 times

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 10:44 am
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

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 12:35 pm
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.

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 2:12 pm
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

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 2:27 pm
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

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 5:29 pm
by Benj
Hi Alan,

I've cracked it, confirmed with a few series of values.
CRC_Calc.fcfx
(9.96 KiB) Downloaded 358 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.

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 6:01 pm
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

Re: Calculating CRC 8 for MLX90614

Posted: Tue Jan 31, 2017 11:15 pm
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 .