error detection algorithms

Nov 30, 2005 6 Replies

Hi,



I am designing and developing a simple communication protocol to communicate a PC with an ATMEL128 microcontroller (the MAVRIC-IIB board) using the RS485. The last block of every message will be the output code of an error detection algorithm, and I am deciding which algorithm would perform the best. At first, I implemented both CRC-CCITT and CRC-16, but I do not know if these algorithms are too hard to calculate for the micro. Which algorithms would you recommend, having in consideration performance/computing requirements?



Thanks



I'm doing the exact same thing, and here's an exerpt from the document I'm writing (the project is my graduation thesis, so I HAVE TO write all this stuff)

"Error detection will be accomplished by using a two bytes CRC code contained in each data packet. The algorithm for CRC generation and validation is the 8-bit Fletcher algorithm, used as a TCP standard (RFC

1145/1146).

The Fletcher algorithm is defined below for a given buffer buffer[N] with N bytes to be checked. Each one of the CRC bytes should be an 8-bit unsigned integer.

crc_a = 0, crc_b = 0

for i=0 to N-1

crc_a = crc_a + buffer[i]

crc_b = crc_b + crc_a

Cheers

Padu

I hope someone teaches you what a CRC is before they let you graduate. The Fletcher checksum is nice, but it's not a CRC.

Brian Dean has some code for MAVRIC-IIB for some communication protocols.

formatting link
I use Mojobus in my book, but there is another one that has a checksum.

-- D. Jay Newman

My trouble is not with the communication protocol. We are working on a specific platform, and we prefer using a specific protocol.

My question is related to checksum algoritms, having in mind that it must run in a microcontroller, so I was asking for the less computing consuming algorithm, but that keeps efficiency high.

"Clifford Heath"

Although technically checksum is not CRC (yes, I know what CRC is), the term CRC is often used in lieu of. Many authors use the term alternatedly. But you right, I probably shouldn't repeat the same error.

Padu

Calculating checksums/CRC's doesn't take as much as you might think. Checksums are as easy as adding each byte to a sum as you send/receive it, possibly with some logic operation between each one (such as ex-or with some constant). CRC's likewise take a few logic operations, and if that's not fast enough they can be sped up using one or more lookup tables. I've done this sort of thing on a Z8, but it was a while back. Look up xmodem/ymodem/zmodem on the Web, there's surely source code floating around. This first ran on 2MHz processsors (though admittedly connected to 300 to 1200 baud modems), I think the algoritms should be fast enough for your app. Today's microcontrollers are faster than yesterday's 8080's.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required