I have got checksum method from a book. that is 1) add all bytes dropping carries (example add all bytes into a byte type variable)
2) takes invert of all bytes sum add 1 (it will be 2's compliment)
3) this will be the checksum
verification:
add all bytes and checksum the answer will the 0
if not it means wrong checksum
problem is that in electronics world many times if there is a problem in PIN that will be low(o). if that is the data pin then all data will be the zero, hence checksum will also be the zero and upon verification it will say correct data arrived. I need its solution.
code of upper algo is as
I have can have data from i2c, spi or manual protocol but this is general checksum method i was using due to this problem i have to revise it. anyway What is the professional checksum method algorithm that results in one byte checksum.
The data is from an actual DS18B20 and the last byte is the CRC byte. After completing the loop, CRC will be the same as the last byte of the data. If you change the loop to 8, the CRC will be zero.
I dont know if you can implement this in your actual application, but if you have the receive device mirror the byte sent it makes it hard not to detect an error.
For example, send the byte 0x34, then wait for an input byte that equals 0x34. If all the pins are stuck low, you'll get 0x00 back instead of 0x34.
If you send 0x00 then you can wait for a mirror of 0xFF or something else. The receiver is responsible for sending the mirror byte back to the transmitter.
The nice thing about this is it doesnt have to use separate pins for input and output if you switch during the sending and receiving.
There are CRC algo's that are pretty good, although it's been a while since i wrote a program for a CRC32 algorithm so i dont remember too much of the theory now. The basic idea is that a single bad byte of data can change the entire crc code rather than just one byte, so it's probably better if you are using a 16 bit CRC code.
Remember also that any 8 bit error detection scheme has a fairly high collision probability, while 16 bit is much better and of course 32 bit is incredibly hard to get the wrong result with.