i don't believe the ascii characters need to be paired up if the even/odd character sums are kept separate.
but i can't make either approach work for the OPs sequence
i don't believe the ascii characters need to be paired up if the even/odd character sums are kept separate.
but i can't make either approach work for the OPs sequence
Tested sketch to calculate checksum from the given data:
void setup()
{
Serial.begin(9600);
byte myData[] = {0x02, 0x30, 0x37, 0x30, 0x30, 0x34, 0x41, 0x31, 0x46, 0x45, 0x37, 0xB5, 0x03};
byte x[5];
for (int i = 1, j = 0; i <= 9; i = i + 2, j++)
{
if (myData[i] > 0x39)
{
myData[i] = myData[i] - 0x37; //getting 0A - 0F
}
if (myData[i+1] > 0x39)
{
myData[i+1] = myData[i+1] - 0x37;
}
x[j] = (myData[i] & 0x0F)<<4 | (myData[i + 1] & 0x0F);
}
byte sum = x[0] ^ x[1] ^ x[2] ^ x[3] ^ x[4]; //XOR operation
Serial.print(sum, HEX); //shows: B5
}
void loop()
{
}
Even simpler:
#define ASCII2HEX(x) (x-'0' < 10 ? x-'0' : x-'A' + 10)
uint8_t rfid[] = {0x30, 0x37, 0x30, 0x30, 0x34, 0x41, 0x31, 0x46, 0x45, 0x37}, cs_lo = 0, cs_hi = 0;
for (int i = 0; i < sizeof(rfid); i+= 2)
{
cs_hi ^= ASCII2HEX(rfid[i]);
cs_lo ^= ASCII2HEX(rfid[i+1]);
}
uint8_t checksum = (cs_hi << 4) | cs_lo;
Serial.print("Checksum = ");
Serial.println(checksum, HEX);
how "+" is implemented in hardware