CCITT in C++ for AVR

Hi,

First of all - I'm a total newbie to AVR or other microcontrollers programming so forgive any mistakes I make.

I am making a school project for PocketPC which is to send some data to mechanic robots controlled by AVRs or other types of microcontrollers (mostly AVR). The data I send is own designed packet, which includes its own 16bit CRC. After some googling I found the CCITT ( poly 0x1021 with

0xFFFF init) and other types of 16bit CRCs (XModem, ARC) - I chose to go with CCITT, but still can go with other type if it makes it easier.

To the subject now - I have no idea what type of compilers are available for such microcontrollers (AVR etc). What I'd like to know is there any library with CCITT (or other) calculation function. I'm aware there are many source codes for that on the web, but I'd still would go with the library function (just easier for the people to use it) - the speed is not an issue. It's just easier to point other people to the lib function in the documentation instead of making them type some code I present in the doc.

Hope I made myself clear.

Reply to
RadGar
Loading thread data ...

I decided to take the winavr gcc compiler. It nicely fits into eclipse as IDE using the CDT. Programming the processor is actually done with AVR studio, which also may be used as IDE for the winavr.

Thats where i cant help you :-). But there should be some code for this problem in the C world.

Regards, Kurt

--
Kurt Harders
PiN -Präsenz im Netz GITmbH
mailto:news@kurt-harders.de
http://www.pin-gmbh.com
Reply to
Kurt Harders

Kurt Harders napisa³(a):

Is there in the AVR studio / winavr built-in lib with such function? If you could check that I'd appreciate. Thanks for such a fast reply, regards

Rafal Mroz

Reply to
RadGar

The CRC algorithm is almost trivial to implement. This search gave over

2 million hits (of which at least some appeared useful)
formatting link

I implemented CRC16 and CRC32 some years ago - took maybe an hour once I had the algorithm in front of me. The polynomial is irrelevant to the fundamental implementation.

It's possible there's a free implementation for AVR - see

formatting link

Cheers

PeteS

Reply to
PeteS

Personally for this application, where the CRC only tells you if the packet got corrupted, I would use something simpler that CCITT. Simply sum the packet bytes and make the check 0x10000 minus this total. On receive, total the packet bytes, add the CDR and check the result is zero.

Ian

Reply to
Ian Bell

The simple CRC verification (since the packet is sent through the TCP) is a good idea - but the choice of CCITT or other more complex CRCs is not mine to make unfortunatelly.

Reply to
RadGar

Last time I wrote a PPP implementation I had little trouble understanding both the 16 and the 32 bit CRCs, described in rfc1662,

formatting link
. I'd just stick with this algorithm, pretty widespread and proven.

Dimiter

------------------------------------------------------ Dimiter Popoff Transgalactic Instruments

formatting link

------------------------------------------------------

Reply to
Didi

I see most replies miss the question I asked so rephrase:

I don't know what sort of software is used to make apps for AVRs (or other) microcontrollers. What I want to know if any of these has a built-in header/lib with a function to calculate CRC CCITT (or other

16bit CRC). The reason for these is for *others* (I'm not going to write an app for the AVR) to just use the function instead of searching for the code on the web (the AVR apps will be tasks for the school, just as my PocketPC sender app is). If there is no built-in function for that I'd just want to verify that and point the people in my documentation to search for the implementation or just hand them over what I'll use. thanks, hope this makes things clear

Rafal Mroz

Reply to
RadGar

The CRC routine is small, simple, and available all over the web. Its just a 512 word table and a couple of dozen lines of C code. Try here.

formatting link

Reply to
diggerdo

I do not understand. You said you 'chose' to go with CCITT.

Ian

Reply to
Ian Bell

Ian Bell napisa?(a):

Well in fact I was the one to choose the CCITT, but the project manager (let's call him that :D) told me to stick with already existing CRCs and gave a CCITT as an example (which was in fact most common to my understanding). So own created 16bit CRC was never an option.

Reply to
RadGar

diggerdo napisa³(a):

I'm know it's small because I've seen implementations (not only table driven), but it's also my task to ensure if there are any ready to use functions for that (in STL, built-in libs). That's the only thing I want to know (if there's no such lib which has such a function I just need to know there isn't). Thanks for the link though - it seems there's no built-in implementation of CCITT calculation. regards,

RadGar

Reply to
RadGar

Now I understand. However, the CRC I described is very common - it would not be your own creation. Furthermore an even simpler version which just uses a single byte CRC is almost certainly available for the AVR as it is the one often used when programming these devices.

ian

Reply to
Ian Bell

#1 mistake is the thought of using C++ in an embedded application such as you describe.

If you must use a solution from a can then at least the 16 bit version comes in avr-libc, the most common library used with avr-gcc.

formatting link

Avr-gcc (including the Windows package of avr-gcc called WinAVR) is a very good C compiler and environment for AVR development.

Reply to
David Kelly

Not my choice.

On comp.lang.c++ I got the link to the avr-libc, but thanks. That's what I was looking for. IMO C is also good, as the OO stuff that comes with C++ is not necessary. Thanks for the info, regards

RadGar

Reply to
RadGar

avr-libc have the following inline assembly functions:

__inline__ uint16_t _crc16_update (uint16_t __crc, uint8_t __data) __inline__ uint16_t _crc_xmodem_update (uint16_t __crc, uint8_t __data) __inline__ uint16_t _crc_ccitt_update (uint16_t __crc, uint8_t __data)

avr-libc is a standard library for use with avr-gcc.

Regards Anton Erasmus

Reply to
Anton Erasmus

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.