I'm start working on RS485 and I need to check the CRC of 5 bytes or compute de checksum that will be transmitted to the bus.
I already done a function that checks it but for my test it is not reliable
byte checkCrc( byte startByte, byte id, byte message1 , byte message2, byte endByte)
{
int crcCalc = startByte +id + message1 + message2 + endByte;
if(crcCalc > 255)crcCalc = crcCalc >>8;
return crcCalc;
}
Any tip how can I do this in a more effective way
Are you trying to validate a CRC or a checksum?
Does this help...
http://www.nongnu.org/avr-libc/user-manual/group__util__crc.html
what is more easly to do in your opinion?
Do you think a checksum would fit for my purpose?
CRCs are far more reliable for detecting the kinds of failures that occur in communications. I have never nor would I ever use a checksum for detecting communications failures.
I will study the CRC then.The link you provide have some good material.I think my answer is there:)
Thanks dude
HugoPT:
what is more easly to do in your opinion?
Do you think a checksum would fit for my purpose?
It depends. CRCs are for error /detection/, especially when trying to extract information from a noisy signal. A checksum is a way to compare (usually longer runs of) values to determine if those values are the same or not. One is great for stream detection, and the other is great for determining some stream you layed down in memory or on disk is the same or not.
The fact is that they are complementary, as they have different applications.