I have record hex record:02000004000107.
My translation of which is 02: no of data bytes; 00000:address field 04:record type extended linear record; 0001:upper 16 bits of the address. 07:expected checksum
I have function to calculate checksum to verify record is good.
unsigned char chk = 02 + 00 + 00 + 01 chk = ~chk + 1 = 0xf9
My checksum is no matching with expected checksum of 07 from record.
My queries: a) Is my translation of record and maths for checksum good? b) if yes, why calculated checkum may not matching? Does it means record is bad?
I think that your interpretation of the fields is correct, and so is your rejection of the checksum.
The sum of all the bytes on the line should be zero (modulo 256).
2 + 4 + 1 + 7 does not make zero, but 2 + 4 + 1 does make 7.
It appears that the software that produced that line added up all the bytes and wrote the sum in the checksum field, they forgot to negate it.