Searching \ for 'CRC16' in subject line. ()
Help us get a faster server
FAQ page: techref.massmind.org/techref/method/errors.htm?key=crc
Search entire site for: 'CRC16'.

Truncated match.
PICList Thread
'CRC16'
1999\04\15@114232 by

I received a private email requesting to explain better CRC16, I think
it may be important for somebody else in the list, so here it goes:

There is only one CRC-16, it was primarily used by IBM at their 3270
Bysinc communication as BSC1 - BSC3 protocols, the algorithm is x^16 +
x^15 + x^2 + 1, it always starts with zeros in the 16 bits register,
there is another CRC that deals with 16 bits, but its name is CRC-CCITT,
x^16 + x^12 + x^5 + 1, also used as FCS from SDLC/HDLC(X.25), also known
as CRC-X25, also used in disk storage systems, the preset can be all
zeros or all ones in both sides, the receiver expect a final CRC-CCITT
inverted bits as "0001110100001111".

The math for CRC16 is simple:

1) zero the 16 bits register.
2) Set a loop of 8 bits
3) shift right the 16 bit register, save the carry bit.
4) shift right the 8 bits tx data, save the carry bit.
5) xor both saved carry bits
6) if result is one, xor 16 bit register with A001h
7) loop back to step 3 (decrement 8 step counter)
8) 16 bits register holds inverted bytes, left x right.

By the rule of thumb, whenever using an algorithm when both carry bits
are compared to generate a secondary xor at the 16 bits register,
feeding the crc partial result back to the calculation ends up in zero
at the 16 bits register. This is obvious, isn't?  This is exactly how
the IBM 3270 machines check CRC, they just incorporate the received CRC
into the calculating CRC, if at the end the result is zero, everything
is ok.

The A001h value above is just the inverted 8005h ([x^16] + x^15 + x^2
+1) used in other algorithms that does the same effect, my solution just
save few programming steps, but requires the inversion when transmitting
the crc.

You can find a program I did for PC-DOS to calculate CRC16, it is
available at my webpage, 8051 download section at http://www.ustr.net
you just type "CRC16 a b c d e f...", abc.. being the hexa bytes you
want to calculate the CRC16. It is nice to verify your new
microcontroller CRC16 routine.

Wagner.

At 11:41 AM 4/15/99 -0400, you wrote:
>I received a private email requesting to explain better CRC16, I think
>it may be important for somebody else in the list, so here it goes:

HOpe that you weren't referring to mine, because I didn't ask. <G>

>There is only one CRC-16, it was primarily used by IBM at their 3270
>...
>there is another CRC that deals with 16 bits, but its name is CRC-CCITT,

That looks like two to me.  One + Another = 2.

>The math for CRC16 is simple:

While the procedure for the two CRC's are identical, the XOR'd value is
not.  This seed may be selected to provide varying characteristics for
errors.  Some media are prone to one error, another to a different (ie, a
missing bit (erasure) is different than a falsely-calculated bit (noise)).
Different seed values are better at picking out one or the other.
Different media tend toward different error types.

>By the rule of thumb, whenever using an algorithm when both carry bits

Not to get OT here, but did you know that the "rule of thumb" came from an
old English law that said you couldn't beat your wife with a rod thicker
than your own thumb?  We've come a long way...

Andy

==================================================================
Montana Design - http://www.montanadesign.com - Electronics & Model Boats
==================================================================

At 11:59 04/15/99 -0400, Andy Kunz wrote:
>>There is only one CRC-16, it was primarily used by IBM at their 3270
>>...
>>there is another CRC that deals with 16 bits, but its name is CRC-CCITT,
>
>That looks like two to me.  One + Another = 2.

i guess what he's saying is that the =one= is called "crc16", while the
=other= is called "crc-ccitt", so one apple + one orange = still one apple
+ one orange (and not two apples :)

there may be cases where people talk about "crc16" (eg. vs "crc32") meaning
all crcs with 16 bits, but i guess "crc16" usually means just this one
algorithm.

ge

Still, CRC-16 is just one, CRC-16 is its name, the other is CRC-CCITT.
CRC-16 is not a generic way to refer to a CRC that deals with 16 bits.
CRC-8, CRC-16, CRC-CCITT and CRC-32 sometimes is refered simply as CRC,
by lack of information.

Andy Kunz wrote:
> >There is only one CRC-16, it was primarily used by IBM at their 3270
> >...
> >there is another CRC that deals with 16 bits, but its name is CRC-CCITT,
>
> That looks like two to me.  One + Another = 2.
>
> Not to get OT here, but did you know that the "rule of thumb" came from an
> old English law that said you couldn't beat your wife with a rod thicker
> than your own thumb?  We've come a long way...

... so the law said you could beat your wife... can you imagine a
English gentleman selecting a rod, comparing to his thumb, because he
needed to spank his wife? and we talk about world injustice... perhaps
we just lost the tail sooner than the others.

On Thu, 15 Apr 1999, Gerhard Fiedler wrote:

> At 11:59 04/15/99 -0400, Andy Kunz wrote:
> >>There is only one CRC-16, it was primarily used by IBM at their 3270
> >>...
> >>there is another CRC that deals with 16 bits, but its name is CRC-CCITT,
> >
>
> i guess what he's saying is that the =one= is called "crc16", while the
> =other= is called "crc-ccitt", so one apple + one orange = still one apple
> + one orange (and not two apples :)

> there may be cases where people talk about "crc16" (eg. vs "crc32") meaning
> all crcs with 16 bits, but i guess "crc16" usually means just this one
> algorithm.

Hi, if I talk about CRC16 I mean *always* all CRC's with 16 bits because
of the algorythm is always the same. There are only 2 differences: which
mask you use (in the example it was A005 if I recall; I use always 1021h
according to the CCITT recommendation), and whether there is a start value
of 0x00 or 0xFF . For the sake of convenience, I include my own CRC
routine for x86 (no fear, it's no longish).

Imre

P.S. The IF NZ construct is self-explanatory. It is coming from the A86
assembler (thank you, Eric Isaacson!).

;
;This subroutine calculates a 16-bit CRC
;Synopsis:  MOV AX,CRC16    ; i/o parameter
;           MOV BL,C        ; char using the update
;           MOV DX,MASK     ; polynomial (e. g. 1021h for CCITT)
;           CALL CRC16
;           MOV CRC16,AX    ; store returned value
;                           ; BX destroyed
;
CRC16:  PUSH    CX,SI       ; save register
XOR     BH,BH       ; clear upper
XCHG    BL,BH       ; into upper
MOV     CX,8        ; set up loop
L1:     MOV     SI,AX       ; temporary save
SAL     AX,1        ; rotate
XOR     SI,BX       ; temporary result
TEST    SI,8000h    ; highest bit
IF NZ   XOR AX,DX   ; if set
SAL     BX,1        ; use operand
LOOP    L1          ; end of loop
POP     SI,CX       ; restore register
RET                 ; return to caller

The use "CRC16" as a generic name for 16 bits CRC is wrong.  This is why
we have first and last name (with middle names sometimes), just to have
an identification. As the CRC-16 and CCITT use the same algorithm with
different bit logic doesn't make them the same.
In a gross example, on comparing the fact that we both have two eyes, a
nose, a mouth, two ears, two arms and two legs, blood as life support
system transport belt, feeding by oxidation of organic material, even
though, people can not call me "Dr. Imre Bartfai" too. :)

I may seems a pest here, but I believe that standards and conventions
were made because it was the best solution at that moment.  Except if I
have an irrefutable explanation (and some times it happens) why things
need to change (from kHz to KHz for example), I need to accept the
standards and use them happily ever after. Without a good reasonably
argument, it is just lack of culture and time. No offense at all here
please, just to remind that the word "culture" means exactly that, "the
learning of standards, history and procedures", something else?

Wagner.

"Dr. Imre Bartfai" wrote:
> Hi, if I talk about CRC16 I mean *always* all CRC's with 16 bits because
> of the algorythm is always the same. There are only 2 differences: which
> mask you use (in the example it was A005 if I recall; I use always 1021h
> according to the CCITT recommendation), and whether there is a start value
> of 0x00 or 0xFF . For the sake of convenience, I include my own CRC
> routine for x86 (no fear, it's no longish).
>
> Imre

Hello,

it sounds good, but ... how would you name the different CRC items
having common algorythm and 16 bit length? In your example it would be the
wording "human" or maybe "male human" :-) ... The sense of the question
is, I think, that if we talk about CRC it is more important to know how
long is the calculated result, and it is less or at the moment not at all
important, which particular polynomial is being chosen. For example: "I
offer for you CRC16 as CRC8 would not be sensitive enough, but CRC32 seems
to be overkill". I elaborated a comparative table for this decision (see
also the "birthday paradox" thread.). The results are interesting, really.

Imre

On Fri, 16 Apr 1999, Wagner Lipnharski wrote:

{Quote hidden}

At 19:11 04/16/99 +0200, Dr. Imre Bartfai wrote:
>On Fri, 16 Apr 1999, Wagner Lipnharski wrote:
>> The use "CRC16" as a generic name for 16 bits CRC is wrong.  This is why
[...]
>it sounds good, but ... how would you name the different CRC items
>having common algorythm and 16 bit length?

i guess wagner used the term you're asking for in his message: "CRC" is the
term for the algorithm, and "16 bit" is the term for the length of the
result, so wagner used "16 bit CRCs" (as opposed to the "proper name" CRC16
for one particular 16 bit crc).

>is, I think, that if we talk about CRC it is more important to know how
>long is the calculated result, and it is less or at the moment not at all
>important, which particular polynomial is being chosen.

i'm not sure; it seems that the selection of the polynomial is rather
crucial for the characteristics of the algorithm -- that's probably why,
from the many, many possibilities to form a 16 bit polynomial, only two are
common.

ge

Dear Imre, I am quite sure that if you say; "I offer for you CRC-16 or
CRC-CCITT, as CRC8 would not be sensitive enough, but CRC32 seems to be
overkill"...everybody that knows what you talking about would understand
perfectly, if they dont understand it... they would not understand it at
all.  Unfortunatelly, CRC-16 has the number 16 in its name, but you can
be sure that when producing a protocol that needs to use 16 bits CRC,
you would need to specify correctly which one it is... as CRC-16 or
CRC-CCITT, if not... somebody can call you later and say... "Hey, you
said you would use CRC-16, and you made it in CRC-CCITT, what the hell
you did here?" ... not nice to hear it after release 5000 units at the
market, huh?

If right now somebody ask you to produce a code tonight, to a
presentation show tomorrow earling morning to close a millionary
business deal, using CRC16... without asking anything else, which one
would you use? CRC-16 or CRC-CCITT...

"Dr. Imre Bartfai" wrote:
{Quote hidden}

The quotation from -> http://www.repairfaq.org/filipg/LINK/F_crc_v3.html

"We have seen that CRC algorithms vary in:
*Width of the poly (polynomial).
*Value of the poly.
*Initial value for the register.
*Whether the bits of each byte are reflected before being
processed.
*Whether the final register value should be reversed (as in
reflected versions).
*Value to XOR with the final register value.
In order to be able to talk about particular CRC algorithms, we need to
able to define them more precisely."

So,
> On Thu, 15 Apr 1999, Gerhard Fiedler wrote:
>
> .......... the =one= is called "crc16", while the
>  =other= is called "crc-ccitt", so one apple + one orange = still one apple
>  + one orange (and not two apples :)
>
it is true.

Kestas
Kaunas, Lithuania

'CRC16'
1999\06\17@061103 by
Hallo,

has anyone an idea for implementing a CRC16 into a PIC16C6X fŸr checking
a serial datastream.
Or does anyone know, where to get an example for a code.

Thanks

Martin Huber

Hallo,

here is the source for your convenience. I use this routine extensively.
Imre
-------------[ Source code follows ]---------------------
; What you need is to define the polynomial. E. g. for the CCITT one:

poly0        equ        0x21
poly1        equ        0x10

; Do not forget to initialize <crcval> = <crch:crcl> before the 1st call
; e. g. with 0xFF or with zeroes, as the particular CRC algorithm
; requires.

;This subroutine calculates a 16-bit CRC
;--------
; CrcUpd: update <crcval> using <W>
;
;
CBLOCK     crcblk
crch
crcl
saved
oldcch
i
ENDC
CrcUpd  movwf   saved           ; j = W
movlw   d'8'            ; W = 8
movwf   i               ; i = W
_loop   movfw   crch
movwf   oldcch          ; temporary save
clrc                    ; clear carry for rlf
rlf     crcl            ; crc << 1
rlf     crch
movfw   saved           ; the char read
xorwf   oldcch,F        ; test with old high
btfss   oldcch,7        ; if bit set, apply mask
b       _notset         ; otherwise skip
movlw   poly0
xorwf   crcl,F
movlw   poly1
xorwf   crch,F
_notset clrc                    ; for rlf
rlf     saved,F         ; next bit of saved
decfsz  i,F
b       _loop
return
;
; End CrcUpd

------------------[End of Code Fragment]-------------------

On Thu, 17 Jun 1999, Martin Huber wrote:

{Quote hidden}

See Dallas Semiconductor Application Note 27:

http://www.dalsemi.com/DocControl/PDFs/app27.pdf

Discusses CRC16 in particular beginning on page 7.

GrŸssen,

Steve

On 17 Jun 99 at 11:58, Martin Huber wrote:

{Quote hidden}

I'm looking for a utility that takes a given data packet with a CRC16,
and decodes the poly used.

ie. TheCRCis 16 <byte1> <byte2> ... <byten>

where 16 is for CRC16 or CRC32, 16 being CRC16
and byte... is a packet ending in the CRC.

Eventually, I need this in PIC code too.  It's for a protocol decoder.

Craig

> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...