Recent

Author Topic: CRC8/Maxim function?  (Read 26269 times)

JCDes

  • New Member
  • *
  • Posts: 23
CRC8/Maxim function?
« on: July 02, 2021, 09:59:24 pm »
Is there a crc8/maxim function available? I'm new to pascal and I just can't get it to work. I have searched and searched but nothing seems to work for me. Or maybe I'm just doing everything wrong. I have a hex editor window and need to generate the crc using the first 14 bytes.  I'm using the following code (opensource from the web):
Code: [Select]
CRC8 byte, normal

var
  CrcTable              : Array[0..255] of Cardinal;

function GenerateTableCrc8(Poly:Cardinal):Cardinal;
var
  i                     : Cardinal;
begin
for i:=0 to 255 do CrcTable[i]:=Crc8(chr(i),Poly,0);
end;

function Crc8Byte(Buffer:String;Initial:Cardinal):Cardinal;
var
  i                     : Cardinal;
begin
Result:=Initial;
for i:=1 to Length(Buffer) do begin
  Result:=(Result shl 8) xor CrcTable[(ord(Buffer[i]) xor (Result)) and $ff];
  end;
Result:=Result and $ff;
end;

I am using $31 as the poly. since I'm such a a noob I get cofused in the order of things.
I am using: mycrc := crc8(hexstring,poly,cardinal); Should I leave cardinal at 0? Or how does it work?

I need to get the first 14 bytes of line $100 and generate the crc8/maxim from that. I'm lost...

I know that the correcr crc for 00258974000022 is $5C since all the online calculators come up with the same value (sunshine, tomeko, crccalc etc.). But I can't seem to find the way.
« Last Edit: July 02, 2021, 10:05:06 pm by JCDes »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: CRC8/Maxim function?
« Reply #1 on: July 02, 2021, 11:03:56 pm »
When you say "can't get it to work", what /exactly/ do you mean? Can't compile? Result wrong? Messages...

Where did you get that code? Is what you've supplied what you're trying to compile (please provide a complete program, not a fragment). Is the sequence to which you're applying a CRC a known test, and why are you confident you know what the result should be?

When I was last looking at this sort of thing I found these useful:

https://fossies.org/linux/peazip/crcmodel.pas
https://fossies.org/linux/peazip/crcm_cat.pas

I ended up implementing a function which could look at an arbitrary sequence and suggest which (known) CRC had been applied to it. I don't think it's in a state where it would be easy to drop your example into it, but overall it's the best collection I've come across.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #2 on: July 03, 2021, 04:30:06 am »
1. My result is wrong.
2. I got that code from http://www.miscel.dk/MiscEl/CRCcalculations.html.
3. I am confident that I know the result because I got the original dump at hand.
4. I am using a script that runs on an a program that runs pascal scripts.

My only obstacle is not being able to generate the crc8/maxim correctly for those 14 bytes. The software seems limited as for pascal commands for example Array[1...255] is not valid so I have to write the whole array which I did already earlier on. this is the whole function that I have so far it runs but does not calculate correctly. Once again I'm new to pascal. This is what I have done so far:
Code: [Select]
function crc8(Buffer:String;Poly,Initial:Cardinal):Cardinal;
var
  i,j                   : Integer;
begin
Result:=Initial;
for i:=1 to Length(Buffer) do begin
  Result:=Result xor ord(buffer[i]);
  for j:=0 to 27 do begin
    if (Result and $80)<>0 then Result:=(Result shl 1) xor $31
    else Result:=Result shl 1;
    end;
  end;
Result:=Result and $ff;
end;

////////////////////////////////////////////////////////////////////////////////

function GenerateTableCrc8(Poly:Cardinal):Cardinal;
var
  i                     : Cardinal;
  CrcTable              : Array of Cardinal;
begin

CRCTABLE :=
 [$00, $31, $62, $53, $C4, $F5, $A6, $97, $B9, $88, $DB, $EA, $7D, $4C, $1F, $2E
, $43, $72, $21, $10, $87, $B6, $E5, $D4, $FA, $CB, $98, $A9, $3E, $0F, $5C, $6D
, $86, $B7, $E4, $D5, $42, $73, $20, $11, $3F, $0E, $5D, $6C, $FB, $CA, $99, $A8
, $C5, $F4, $A7, $96, $01, $30, $63, $52, $7C, $4D, $1E, $2F, $B8, $89, $DA, $EB
, $3D, $0C, $5F, $6E, $F9, $C8, $9B, $AA, $84, $B5, $E6, $D7, $40, $71, $22, $13
, $7E, $4F, $1C, $2D, $BA, $8B, $D8, $E9, $C7, $F6, $A5, $94, $03, $32, $61, $50
, $BB, $8A, $D9, $E8, $7F, $4E, $1D, $2C, $02, $33, $60, $51, $C6, $F7, $A4, $95
, $F8, $C9, $9A, $AB, $3C, $0D, $5E, $6F, $41, $70, $23, $12, $85, $B4, $E7, $D6
, $7A, $4B, $18, $29, $BE, $8F, $DC, $ED, $C3, $F2, $A1, $90, $07, $36, $65, $54
, $39, $08, $5B, $6A, $FD, $CC, $9F, $AE, $80, $B1, $E2, $D3, $44, $75, $26, $17
, $FC, $CD, $9E, $AF, $38, $09, $5A, $6B, $45, $74, $27, $16, $81, $B0, $E3, $D2
, $BF, $8E, $DD, $EC, $7B, $4A, $19, $28, $06, $37, $64, $55, $C2, $F3, $A0, $91
, $47, $76, $25, $14, $83, $B2, $E1, $D0, $FE, $CF, $9C, $AD, $3A, $0B, $58, $69
, $04, $35, $66, $57, $C0, $F1, $A2, $93, $BD, $8C, $DF, $EE, $79, $48, $1B, $2A
, $C1, $F0, $A3, $92, $05, $34, $67, $56, $78, $49, $1A, $2B, $BC, $8D, $DE, $EF
, $82, $B3, $E0, $D1, $46, $77, $24, $15, $3B, $0A, $59, $68, $FF, $CE, $9D, $AC];

for i := $0 to $FF do CrcTable[i]:=Crc8(chr(i),$31,0);
end;

////////////////////////////////////////////////////////////////////////////////

function Crc8Byte(Buffer:String;Initial:Cardinal):Cardinal;
var
  i                     : Cardinal;
  crctable: array of cardinal;
begin
CRCTABLE :=
 [$00, $31, $62, $53, $C4, $F5, $A6, $97, $B9, $88, $DB, $EA, $7D, $4C, $1F, $2E
, $43, $72, $21, $10, $87, $B6, $E5, $D4, $FA, $CB, $98, $A9, $3E, $0F, $5C, $6D
, $86, $B7, $E4, $D5, $42, $73, $20, $11, $3F, $0E, $5D, $6C, $FB, $CA, $99, $A8
, $C5, $F4, $A7, $96, $01, $30, $63, $52, $7C, $4D, $1E, $2F, $B8, $89, $DA, $EB
, $3D, $0C, $5F, $6E, $F9, $C8, $9B, $AA, $84, $B5, $E6, $D7, $40, $71, $22, $13
, $7E, $4F, $1C, $2D, $BA, $8B, $D8, $E9, $C7, $F6, $A5, $94, $03, $32, $61, $50
, $BB, $8A, $D9, $E8, $7F, $4E, $1D, $2C, $02, $33, $60, $51, $C6, $F7, $A4, $95
, $F8, $C9, $9A, $AB, $3C, $0D, $5E, $6F, $41, $70, $23, $12, $85, $B4, $E7, $D6
, $7A, $4B, $18, $29, $BE, $8F, $DC, $ED, $C3, $F2, $A1, $90, $07, $36, $65, $54
, $39, $08, $5B, $6A, $FD, $CC, $9F, $AE, $80, $B1, $E2, $D3, $44, $75, $26, $17
, $FC, $CD, $9E, $AF, $38, $09, $5A, $6B, $45, $74, $27, $16, $81, $B0, $E3, $D2
, $BF, $8E, $DD, $EC, $7B, $4A, $19, $28, $06, $37, $64, $55, $C2, $F3, $A0, $91
, $47, $76, $25, $14, $83, $B2, $E1, $D0, $FE, $CF, $9C, $AD, $3A, $0B, $58, $69
, $04, $35, $66, $57, $C0, $F1, $A2, $93, $BD, $8C, $DF, $EE, $79, $48, $1B, $2A
, $C1, $F0, $A3, $92, $05, $34, $67, $56, $78, $49, $1A, $2B, $BC, $8D, $DE, $EF
, $82, $B3, $E0, $D1, $46, $77, $24, $15, $3B, $0A, $59, $68, $FF, $CE, $9D, $AC];

Result := Initial;
for i := 1 to Length(Buffer) do begin
  Result := (Result shl 8) xor CrcTable[(ord(Buffer[i]) xor (Result)) and $ff];
  end;
Result := Result and $ff;
end;

Then I'm using it like this:
Code: [Select]
Var1 :=
    IntToHex(GetByteHexEdit($00),2) +  IntToHex(GetByteHexEdit($01),2) +  IntToHex(GetByteHexEdit($02),2)
+  IntToHex(GetByteHexEdit($03),2) +  IntToHex(GetByteHexEdit($04),2) +  IntToHex(GetByteHexEdit($05),2)
+  IntToHex(GetByteHexEdit($06),2) +  IntToHex(GetByteHexEdit($07),2) +  IntToHex(GetByteHexEdit($08),2)
+  IntToHex(GetByteHexEdit($0A),2) +  IntToHex(GetByteHexEdit($0B),2) +  IntToHex(GetByteHexEdit($0C),2)
+  IntToHex(GetByteHexEdit($0D),2);

Var1 := Crc8byte(var1,0);
SetByteHexEdit ($11F,Var1);

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: CRC8/Maxim function?
« Reply #3 on: July 03, 2021, 08:24:26 am »
What EXACTLY goes wrong? Please give us a COMPLETE program and some test data to work with.

Look, I want to help but I've got some important bookkeeping work to do. Pretty much everybody else has other demands on their time.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avk

  • Hero Member
  • *****
  • Posts: 825
Re: CRC8/Maxim function?
« Reply #4 on: July 03, 2021, 04:42:01 pm »
Googling shows that CRC8/Maxim uses the following parameters:
Code: Text  [Select][+][-]
  1.   CRC polynomial: $31
  2.   Initial value:  $00
  3.   Final xormask:  $00
  4.   Reflect input:  True
  5.   Reflect output: True
  6.  
Accordingly, the function should be like this:
Code: Pascal  [Select][+][-]
  1. function Crc8Maxim(aData: PByte; aSize: SizeInt): Cardinal;
  2.   function ReflectLoByte(aValue: Cardinal): Cardinal; inline;
  3.   begin
  4.     aValue :=        (aValue and $f0) shr 4 or (aValue and $0f) shl 4;
  5.     aValue :=        (aValue and $cc) shr 2 or (aValue and $33) shl 2;
  6.     ReflectLoByte := (aValue and $aa) shr 1 or (aValue and $55) shl 1;
  7.   end;
  8. var
  9.   I, J: SizeInt;
  10. begin
  11.   Result := 0;
  12.   for I := 0 to Pred(aSize) do
  13.     begin
  14.       Result := Result xor ReflectLoByte(Cardinal(aData[I]));
  15.       for J := 1 to 8 do
  16.         Result := Result shl 1 xor $31 and SarShortInt(Result, 7);
  17.     end;
  18.   Result := ReflectLoByte(Result) and $ff;
  19. end;
  20.  
Or a faster version using a lookup table:
Code: Pascal  [Select][+][-]
  1. const
  2.   CrcTable: array[Byte] of Cardinal = (
  3.     $00, $5e, $bc, $e2, $61, $3f, $dd, $83, $c2, $9c, $7e, $20, $a3, $fd, $1f, $41,
  4.     $9d, $c3, $21, $7f, $fc, $a2, $40, $1e, $5f, $01, $e3, $bd, $3e, $60, $82, $dc,
  5.     $23, $7d, $9f, $c1, $42, $1c, $fe, $a0, $e1, $bf, $5d, $03, $80, $de, $3c, $62,
  6.     $be, $e0, $02, $5c, $df, $81, $63, $3d, $7c, $22, $c0, $9e, $1d, $43, $a1, $ff,
  7.     $46, $18, $fa, $a4, $27, $79, $9b, $c5, $84, $da, $38, $66, $e5, $bb, $59, $07,
  8.     $db, $85, $67, $39, $ba, $e4, $06, $58, $19, $47, $a5, $fb, $78, $26, $c4, $9a,
  9.     $65, $3b, $d9, $87, $04, $5a, $b8, $e6, $a7, $f9, $1b, $45, $c6, $98, $7a, $24,
  10.     $f8, $a6, $44, $1a, $99, $c7, $25, $7b, $3a, $64, $86, $d8, $5b, $05, $e7, $b9,
  11.     $8c, $d2, $30, $6e, $ed, $b3, $51, $0f, $4e, $10, $f2, $ac, $2f, $71, $93, $cd,
  12.     $11, $4f, $ad, $f3, $70, $2e, $cc, $92, $d3, $8d, $6f, $31, $b2, $ec, $0e, $50,
  13.     $af, $f1, $13, $4d, $ce, $90, $72, $2c, $6d, $33, $d1, $8f, $0c, $52, $b0, $ee,
  14.     $32, $6c, $8e, $d0, $53, $0d, $ef, $b1, $f0, $ae, $4c, $12, $91, $cf, $2d, $73,
  15.     $ca, $94, $76, $28, $ab, $f5, $17, $49, $08, $56, $b4, $ea, $69, $37, $d5, $8b,
  16.     $57, $09, $eb, $b5, $36, $68, $8a, $d4, $95, $cb, $29, $77, $f4, $aa, $48, $16,
  17.     $e9, $b7, $55, $0b, $88, $d6, $34, $6a, $2b, $75, $97, $c9, $4a, $14, $f6, $a8,
  18.     $74, $2a, $c8, $96, $15, $4b, $a9, $f7, $b6, $e8, $0a, $54, $d7, $89, $6b, $35);
  19.  
  20. function Crc8Maxim(aData: PByte; aSize: SizeInt): Cardinal;
  21. var
  22.   I: SizeInt;
  23. begin
  24.   Result := 0;
  25.   for I := 0 to Pred(aSize) do
  26.     Result := CrcTable[Result xor aData[I]];
  27. end;
  28.  

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #5 on: July 03, 2021, 06:42:02 pm »
I really appreciate your guidance. This software that I'm using allows the user to write our own scripts (which is what I'm trying to do) I have written many others but never a crc function or procedure. Maybe that is the source of my problem? TMS Scripts seem to run on limited libraries and types.

For Example nested functions return syntax error, const CrcTable: array[Byte] of Cardinal = also returns syntax error.

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #6 on: July 03, 2021, 06:54:41 pm »
[0..255] errors out also as syntax error...

I found some more info about the scripter:

VarArrayCreate
VarArrayHighBound
VarArrayLowBound



function SetOf(array): integer; //Returns the current scripter component.


MyFontStyle := SetOf([fsBold, fsItalic]);//Returns a set from the array passed. For example:

Pascal syntax supports:
begin .. end constructor
procedure and function declarations
if .. then .. else constructor
for .. to .. do .. step constructor
while .. do constructor
repeat .. until constructor
try .. except and try .. finally blocks
case statements
array constructors (x:=[ 1, 2, 3 ];)
^ , * , / , and , + , - , or , <> , >=, <= , = , > , < , div , mod , xor , shl , shr operators
access to object properties and methods ( ObjectName.SubObject.Property )

Arrays
Script support array constructors and support to variant arrays. To construct an array, use "[" and "]"
chars. You can construct multi-index array nesting array constructors. You can then access arrays
using indexes. If array is multi-index, separate indexes using ",".
If variable is a variant array, script automatically support indexing in that variable. A variable is a variant
array is it was assigned using an array constructor, if it is a direct reference to a Delphi variable which
is a variant array (see Delphi integration later) or if it was created using VarArrayCreate procedure.
Arrays in script are 0-based index. Some examples:
NewArray := [ 2,4,6,8 ];
Num:=NewArray[1]; //Num receives "4"
MultiArray := [ ['green','red','blue'] , ['apple','orange','lemon'] ];
Str:=MultiArray[0,2]; //Str receives 'blue'
MultiArray[1,1]:='new orange';

Indexes
Strings, arrays and array properties can be indexed using "[" and "]" chars. For example, if Str is a
string variable, the expression Str[3] returns the third character in the string denoted by Str, while Str[I
+ 1] returns the character immediately after the one indexed by I. More examples:
MyChar:=MyStr[2];
MyStr[1]:='A';
MyArray[1,2]:=1530;
Lines.Strings[2]:='Some text';
« Last Edit: July 03, 2021, 06:58:48 pm by JCDes »

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #7 on: July 03, 2021, 06:57:34 pm »
What EXACTLY goes wrong? Please give us a COMPLETE program and some test data to work with.

Look, I want to help but I've got some important bookkeeping work to do. Pretty much everybody else has other demands on their time.

MarkMLl

Basically what goes wrong is that due to my lack of knowledge I am getting a wrong value for the crc calculation result. No errors just a bad calculation and maybe a tms scripter that uses limited pascal syntax.

avk

  • Hero Member
  • *****
  • Posts: 825
Re: CRC8/Maxim function?
« Reply #8 on: July 03, 2021, 07:29:19 pm »
Never used TMS Scripter. Curious, but will such a code be workable?
Code: Pascal  [Select][+][-]
  1. function Crc8Maxim(Buffer: string):Cardinal;
  2. var
  3.   CrcTable: array of Cardinal;
  4.   I: LongInt;
  5. begin
  6.   CrcTable := [
  7.     $00, $5e, $bc, $e2, $61, $3f, $dd, $83, $c2, $9c, $7e, $20, $a3, $fd, $1f, $41,
  8.     $9d, $c3, $21, $7f, $fc, $a2, $40, $1e, $5f, $01, $e3, $bd, $3e, $60, $82, $dc,
  9.     $23, $7d, $9f, $c1, $42, $1c, $fe, $a0, $e1, $bf, $5d, $03, $80, $de, $3c, $62,
  10.     $be, $e0, $02, $5c, $df, $81, $63, $3d, $7c, $22, $c0, $9e, $1d, $43, $a1, $ff,
  11.     $46, $18, $fa, $a4, $27, $79, $9b, $c5, $84, $da, $38, $66, $e5, $bb, $59, $07,
  12.     $db, $85, $67, $39, $ba, $e4, $06, $58, $19, $47, $a5, $fb, $78, $26, $c4, $9a,
  13.     $65, $3b, $d9, $87, $04, $5a, $b8, $e6, $a7, $f9, $1b, $45, $c6, $98, $7a, $24,
  14.     $f8, $a6, $44, $1a, $99, $c7, $25, $7b, $3a, $64, $86, $d8, $5b, $05, $e7, $b9,
  15.     $8c, $d2, $30, $6e, $ed, $b3, $51, $0f, $4e, $10, $f2, $ac, $2f, $71, $93, $cd,
  16.     $11, $4f, $ad, $f3, $70, $2e, $cc, $92, $d3, $8d, $6f, $31, $b2, $ec, $0e, $50,
  17.     $af, $f1, $13, $4d, $ce, $90, $72, $2c, $6d, $33, $d1, $8f, $0c, $52, $b0, $ee,
  18.     $32, $6c, $8e, $d0, $53, $0d, $ef, $b1, $f0, $ae, $4c, $12, $91, $cf, $2d, $73,
  19.     $ca, $94, $76, $28, $ab, $f5, $17, $49, $08, $56, $b4, $ea, $69, $37, $d5, $8b,
  20.     $57, $09, $eb, $b5, $36, $68, $8a, $d4, $95, $cb, $29, $77, $f4, $aa, $48, $16,
  21.     $e9, $b7, $55, $0b, $88, $d6, $34, $6a, $2b, $75, $97, $c9, $4a, $14, $f6, $a8,
  22.     $74, $2a, $c8, $96, $15, $4b, $a9, $f7, $b6, $e8, $0a, $54, $d7, $89, $6b, $35];
  23.  
  24.   Result := 0;
  25.   for I := 1 to Length(Buffer) do
  26.     Result := CrcTable[Result xor Ord(Buffer[I])];
  27. end;
  28.  

MarkMLl

  • Hero Member
  • *****
  • Posts: 8525
Re: CRC8/Maxim function?
« Reply #9 on: July 03, 2021, 08:16:51 pm »
Basically what goes wrong is that due to my lack of knowledge I am getting a wrong value for the crc calculation result. No errors just a bad calculation and maybe a tms scripter that uses limited pascal syntax.

So you're not using FPC (Free or Florian's Pascal compiler... that's obviously going to be a problem since generally speaking people here are going to be using FPC's extended syntax to define array contents etc... you'll probably need to populate arrays using code rather than as a constant.

Please could we have your test data so that we can see what your test cases are vs your expected results.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avk

  • Hero Member
  • *****
  • Posts: 825
Re: CRC8/Maxim function?
« Reply #10 on: July 04, 2021, 05:11:04 am »
BTW, CRC8/Maxim has a check value of $a1, that is, the Crc8Maxim('123456789') function should return $a1.

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #11 on: July 05, 2021, 05:59:13 pm »
Never used TMS Scripter. Curious, but will such a code be workable?
Code: Pascal  [Select][+][-]
  1. function Crc8Maxim(Buffer: string):Cardinal;
  2. var
  3.   CrcTable: array of Cardinal;
  4.   I: LongInt;
  5. begin
  6.   CrcTable := [
  7.     $00, $5e, $bc, $e2, $61, $3f, $dd, $83, $c2, $9c, $7e, $20, $a3, $fd, $1f, $41,
  8.     $9d, $c3, $21, $7f, $fc, $a2, $40, $1e, $5f, $01, $e3, $bd, $3e, $60, $82, $dc,
  9.     $23, $7d, $9f, $c1, $42, $1c, $fe, $a0, $e1, $bf, $5d, $03, $80, $de, $3c, $62,
  10.     $be, $e0, $02, $5c, $df, $81, $63, $3d, $7c, $22, $c0, $9e, $1d, $43, $a1, $ff,
  11.     $46, $18, $fa, $a4, $27, $79, $9b, $c5, $84, $da, $38, $66, $e5, $bb, $59, $07,
  12.     $db, $85, $67, $39, $ba, $e4, $06, $58, $19, $47, $a5, $fb, $78, $26, $c4, $9a,
  13.     $65, $3b, $d9, $87, $04, $5a, $b8, $e6, $a7, $f9, $1b, $45, $c6, $98, $7a, $24,
  14.     $f8, $a6, $44, $1a, $99, $c7, $25, $7b, $3a, $64, $86, $d8, $5b, $05, $e7, $b9,
  15.     $8c, $d2, $30, $6e, $ed, $b3, $51, $0f, $4e, $10, $f2, $ac, $2f, $71, $93, $cd,
  16.     $11, $4f, $ad, $f3, $70, $2e, $cc, $92, $d3, $8d, $6f, $31, $b2, $ec, $0e, $50,
  17.     $af, $f1, $13, $4d, $ce, $90, $72, $2c, $6d, $33, $d1, $8f, $0c, $52, $b0, $ee,
  18.     $32, $6c, $8e, $d0, $53, $0d, $ef, $b1, $f0, $ae, $4c, $12, $91, $cf, $2d, $73,
  19.     $ca, $94, $76, $28, $ab, $f5, $17, $49, $08, $56, $b4, $ea, $69, $37, $d5, $8b,
  20.     $57, $09, $eb, $b5, $36, $68, $8a, $d4, $95, $cb, $29, $77, $f4, $aa, $48, $16,
  21.     $e9, $b7, $55, $0b, $88, $d6, $34, $6a, $2b, $75, $97, $c9, $4a, $14, $f6, $a8,
  22.     $74, $2a, $c8, $96, $15, $4b, $a9, $f7, $b6, $e8, $0a, $54, $d7, $89, $6b, $35];
  23.  
  24.   Result := 0;
  25.   for I := 1 to Length(Buffer) do
  26.     Result := CrcTable[Result xor Ord(Buffer[I])];
  27. end;
  28.  

No errors at all... But The result is not the expected one.

00 00 00 05 00 00 00 00 00 00 00 00 00 00  is giving me "5A"

When I check against the crc8/maxim online calculators the result is "AA" just like the original dump I have.

https://tomeko.net/online_tools/crc8.php?lang=en
https://crccalc.com/
http://www.sunshine2k.de/coding/javascript/crc/crc_js.html


« Last Edit: July 05, 2021, 06:13:18 pm by JCDes »

avk

  • Hero Member
  • *****
  • Posts: 825
Re: CRC8/Maxim function?
« Reply #12 on: July 05, 2021, 07:02:10 pm »
I assume your string(00 00 00 05 00 00 00 00 00 00 00 00 00 00) is a sequence of bytes in hexadecimal notation.
It can be represented as an array of bytes
  b = [0,0,0,5,0,0,0,0,0,0,0,0,0,0],
or the string
  s = #0#0#0#5#0#0#0#0#0#0#0#0#0#0,
for both array and string, Crc8Maxim() (any of the above) returns $aa.

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #13 on: July 06, 2021, 01:40:55 am »
Yes it is a a sequence of bytes in hex notation that I read from an eeprom dump. It is never the same sequence.
« Last Edit: July 06, 2021, 02:33:41 am by JCDes »

JCDes

  • New Member
  • *
  • Posts: 23
Re: CRC8/Maxim function?
« Reply #14 on: July 06, 2021, 03:42:34 am »
It's 8 bit... Every eeprom dump that I verify against the three online crc8/maxim generators give me the same results on the specific lines. I even modify the values and use the online generators and get no errors on the hardware display when I write the eeprom and solder back to the board with modified values. Maybe I'm reading the bytes wrong?

 

TinyPortal © 2005-2018