CCITT in C++ for AVR

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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.

Re: CCITT in C++ for AVR
Hello,


Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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
We've slightly trimmed the long signature. Click to see the full one.
Re: CCITT in C++ for AVR
Kurt Harders napisa³(a):
Quoted text here. Click to load it

  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

Re: CCITT in C++ for AVR
The CRC algorithm is almost trivial to implement. This search gave over
2 million hits (of which at least some appeared useful)
http://www.google.com/search?hl=en&lr=&q=crc+implementation+c&btnG=Search

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
http://www.avrfreaks.net /

Cheers

PeteS


Re: CCITT in C++ for AVR

Quoted text here. Click to load it

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

Re: CCITT in C++ for AVR
Ian Bell napisał(a):
Quoted text here. Click to load it

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.

Re: CCITT in C++ for AVR

Quoted text here. Click to load it

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

Ian

Re: CCITT in C++ for AVR
Ian Bell napisał(a):
Quoted text here. Click to load it

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.

Re: CCITT in C++ for AVR

Quoted text here. Click to load it

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

Re: CCITT in C++ for AVR
Last time I wrote a PPP implementation I had little trouble
understanding both the 16 and the 32 bit CRCs, described
in rfc1662, http://www.ietf.org/rfc/rfc1662.txt .
I'd just stick with this algorithm, pretty widespread and
proven.

Dimiter

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

http://www.tgi-sci.com
------------------------------------------------------


Re: CCITT in C++ for AVR
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

Re: CCITT in C++ for AVR
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. http://www.programmersheaven.com/zone3/cat846/index.htm

Quoted text here. Click to load it



Re: CCITT in C++ for AVR
diggerdo napisa³(a):
Quoted text here. Click to load it

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

Re: CCITT in C++ for AVR

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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.
http://www.nongnu.org/avr-libc/user-manual/group__util__crc.html

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

Re: CCITT in C++ for AVR
Quoted text here. Click to load it

Not my choice.

Quoted text here. Click to load it

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

Re: CCITT in C++ for AVR

Quoted text here. Click to load it

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


Site Timeline