PDA

View Full Version : Rx validation of checksum



archendekta
- 2nd November 2009, 21:37
CALC_Checksum1:
Checksum1 = 0
WORD_HOLD = 0
for i = 3 to MAX_LEN
Word_Hold = Word_Hold + tx_data1(i)
next
Checksum1 = WORD_HOLD.byte0 ^ $FF
RETURN

CALC_Checksum2:
Checksum2 = 0
for i = 3 to MAX_LEN
Checksum2 = Checksum2 + tx_data1(i)
next
Checksum2 = Checksum2 // 256
'Checksum2 = -Checksum2
RETURN



the above routines i pieced together from other posts here to genereate a checksum for transimitted data packets.

to validate on the received end, do i run the same routine and compare values to see if the checksums are equal?

Ioannis
- 3rd November 2009, 20:39
Yes you do.

But instead of this double checksum i'd prefer the 16 bit CRC check. More reliable.

Look here for the fast sub routine from the usual suspect:

http://www.picbasic.co.uk/forum/showthread.php?t=11790

Ioannis

archendekta
- 4th November 2009, 02:43
Thanks Ioannis.

Indeed, DT's looks quite fast. a handy routine i'll "borrow" into me tool box.

btw, i would use [either or] of my sub-routines, not both at the same time.

Cheers!