Home WTI User's Guides

# 5.1. Calculation

There are two methods of CRC calculation on an incoming string of data:

Method 1: Calculate the transmitted CRC on the string of data, excluding the CRC code, and compare the resulting CRC with the received CRC. In this case, two bytes of "00" are appended to the received data before calculation.

Method 2: Calculate the CRC on the transmitted string of data, including the CRC code, and compare the resulting new CRC code to "00 00".

The example calculations for Method 1 and 2 are performed on a single ASCII character "T" (54 HEX).

Example calculation using Method #1:

\$54 \$00 \$00 Message M(x) 01010100 00000000 00000000 Constant P(x) 1000100 00001000 01

Remainder R(x) .010000 00001000 0100 P(x) 10001 00000010 0001

R(x) .0001 00001010 01010000 P(x) 1 00010000 00100001

R(x) . 00011010 01110001 = 1A71 HEX

Example calculation using Method #2:

\$54 \$1A \$71 Message M(x) 01010100 00011010 01110001 Constant P(x) 1000100 00001000 01

Remainder R(x) .010000 00010010 0011 P(x) 10001 00010010 0001

R(x) .0001 00010000 00100001 P(x) 1 00010000 00100001

R(x) . 00000000 00000000 = 0000 HEX

Note:

The "." in the above examples is used to replace the 17th bit of the remainder. This bit is always the result of an XOR between the 17th bit of the constant and a "1" bit in the message data. It is always equal to 0. This bit is not considered part of the CRC code.

Although it may seem that the 17 bit XOR function must be performed in this calculation, a 16 bit accumulator or two eight bit accumulators are all that are needed. The first two bytes of the message are loaded in the 16 bit accumulator and shifted left until a "1" bit shifts into the carry. Then a 16 bit XOR is performed on the data using the constant 1021 HEX. The 17th bit will always be 0 and can be ignored. Each time the accumulator is shifted left, the rest of the message is also shifted, MSB first, into the right side of the accumulator.

Note:

When CRC checking is used in one of the ASCII modes, the modem port should be set to eight bits, no parity in order to receive all bits of the CRC.

The CRC code on seven bit data is verified as follows:

1                     Calculate the CRC of the data bytes with the eighth bit stripped off (eighth bit = 0).

2                     Method #2 must be used for the CRC calculation; the full 16 bits of the CRC code are not transmitted.

3                     When calculating CRC bytes, compare them to the received CRC bytes, excluding the eighth bit of each byte. Mask off the eighth bit of both the calculated and received CRC bytes and compare the remaining seven bits of each byte.