What type of CRC/checksum is this ?

Hi,

I am trying to decode/understand a serial (UART) communication protocol between a PC app and a "device".
I have connected a UART spy on the lines so I can see what is there.
What I got so far is the baudrate, parity, number of bits, stop bits.
The communication is in plain text, with requests from PC and responses from "device".
A request/response packet starts with '(' and ends with ')' char.

The last 2 chars, before the ending ')' char, is some sort of 8 bit CRC or checksum. But I can't figure out what sort of algorithm is used to compute this CRC/checksum.

Example of packet, with 10 char sent over UART interface:

(R1020061)

in hexa, these 10 Bytes transmitted are:

0x28 0x52 0x31 0x30 0x32 0x30 0x30 0x36 0x31 0x29
(    R    1    0    2    0    0    6    1    )

0200 is some kind of 16 bit hex address (0x0200).
The last 2 chars at the ending, before the terminal ')' char, are 6 and 1.
This appears to be the 8 bit hex number 0x61. This is some sort of 8 bit CRC/checksum.
But how is this computed ?

I have several examples of packets, with different CRC/checksum:

(R22A0013)
(R22C0011)
(R2460062)
(R248006C)
(R2570062)
(R25B0017)
(R269006F)
(R26D0012)
(R26F0010)

(R1020061)
(R1040067)
(R1050066)
(R1060065)
(R1070064)
(R108006B)
(R109006A)
(R10A0012)
(R10B0011)
(R10C0010)
(R10D0017)
(R10E0016)
(R10F0015)
(R1100062)
(R1110063)
(R1120060)
(R1130061)
(R1150067)
(R1160064)
(R119006B)
(R11A0013)
(R12F0017)
(R1340064)
(R1350065)
(R1360066)
(R1370067)
(R13C0013)
(R1450062)
(R14A0016)
(R14B0015)
(R14C0014)
(R14D0013)
(R14E0012)

(R4300065)
(R438006D)
(R43D0011)
(R4410063)
(R4750064)
(R4710060)
(R4790068)

Anyone knows how to compute the CRC/checksum at the end of these packets ?

Thanks.

I see several message cases where the last two characters are the same, but the preceding text is different. Therefore the last two characters are not a check sum. Don't know what they are without you identifying the device.

Paul

taribo_m:
The last 2 chars, before the ending ')' char, is some sort of 8 bit CRC or checksum. But I can't figure out what sort of algorithm is used to compute this CRC/checksum.

Looks like a pretty simple XOR checksum (parity byte or parity word).
For testing I made some simple Sketch to check the example packets you provided in your post:

// Very simple XOR checksum
// Test data:
char myData[][7] = {"R10200", 
"R22A00",
"R22C00",
"R24600",
"R24800",
"R25700",
"R25B00",
"R26900",
"R26D00",
"R26F00",
"R10200",
"R10400",
"R10500",
"R10600",
"R10700",
"R10800",
"R10900",
"R10A00",
"R10B00",
"R10C00",
"R10D00",
"R10E00",
"R10F00",
"R11000",
"R11100",
"R11200",
"R11300",
"R11500",
"R11600",
"R11900",
"R11A00",
"R12F00",
"R13400",
"R13500",
"R13600",
"R13700",
"R13C00",
"R14500",
"R14A00",
"R14B00",
"R14C00",
"R14D00",
"R14E00",
"R43000",
"R43800",
"R43D00",
"R44100",
"R47500",
"R47100",
"R47900" };

void setup() {
  Serial.begin(9600);
  for (int i=0; i<50; i++) {
    Serial.print("Data: ");
    Serial.print(myData[i]);
    // XOR all the bytes:
    char checksum = myData[i][0] ^ myData[i][1] ^ myData[i][2] ^ myData[i][3] ^ myData[i][4] ^ myData[i][5];
    Serial.print(" checksum: 0x");
    Serial.print(checksum, HEX);
    Serial.println();
  }
}

void loop() {}

The result:

Data: R10200 checksum: 0x61
Data: R22A00 checksum: 0x13
Data: R22C00 checksum: 0x11
Data: R24600 checksum: 0x62
Data: R24800 checksum: 0x6C
Data: R25700 checksum: 0x62
Data: R25B00 checksum: 0x17
Data: R26900 checksum: 0x6F
Data: R26D00 checksum: 0x12
Data: R26F00 checksum: 0x10
Data: R10200 checksum: 0x61
Data: R10400 checksum: 0x67
Data: R10500 checksum: 0x66
Data: R10600 checksum: 0x65
Data: R10700 checksum: 0x64
Data: R10800 checksum: 0x6B
Data: R10900 checksum: 0x6A
Data: R10A00 checksum: 0x12
Data: R10B00 checksum: 0x11
Data: R10C00 checksum: 0x10
Data: R10D00 checksum: 0x17
Data: R10E00 checksum: 0x16
Data: R10F00 checksum: 0x15
Data: R11000 checksum: 0x62
Data: R11100 checksum: 0x63
Data: R11200 checksum: 0x60
Data: R11300 checksum: 0x61
Data: R11500 checksum: 0x67
Data: R11600 checksum: 0x64
Data: R11900 checksum: 0x6B
Data: R11A00 checksum: 0x13
Data: R12F00 checksum: 0x17
Data: R13400 checksum: 0x64
Data: R13500 checksum: 0x65
Data: R13600 checksum: 0x66
Data: R13700 checksum: 0x67
Data: R13C00 checksum: 0x13
Data: R14500 checksum: 0x62
Data: R14A00 checksum: 0x16
Data: R14B00 checksum: 0x15
Data: R14C00 checksum: 0x14
Data: R14D00 checksum: 0x13
Data: R14E00 checksum: 0x12
Data: R43000 checksum: 0x65
Data: R43800 checksum: 0x6D
Data: R43D00 checksum: 0x11
Data: R44100 checksum: 0x63
Data: R47500 checksum: 0x64
Data: R47100 checksum: 0x60
Data: R47900 checksum: 0x68

This gives the same as in the example data you provided.

1 Like

Looks like a pretty simple XOR checksum (parity byte or parity word).

Thanks a lot uxomm. I don't know how I missed that. I swear XOR was first on my list :slight_smile: ... and I have tried several combinations and types of checksums and CRC, with different polynomial.