Rockwell Automation 440R MSR300 Modular Safety Control System User Manual

Page 80

Advertising
background image

MSR300 Safety System Manual


Rockwell Automation

MSR300 Manual.doc

Pg 80 of 85

9.3

CRC Generation (Code Examples)


CRC Calculation Basics

The CRC calculation is started by first preloading a 16-bit register to all 1’s. Then a
process begins of applying successive eight-bit bytes of the message to the current
contents of the register. During generation of the CRC, each eight-bit character is XORed
with the current register contents. The result is shifted in the direction of the least
significant bit (LSB), with a zero filled into the most significant bit (MSB) position. The LSB
is extracted and examined. If the LSB is a 1, the register is XORed with a preset, fixed
value. If the LSB was a 0, no XOR takes place. This process is repeated until eight shifts
have been performed. After the last (eighth) shift, the above process repeats for the next
byte in the message. After all bytes of the message have been applied, the final content
of the register is the CRC value.

Step by Step:
1. Load a 16-bit register with 0xFFFF (all 1's). Call this the CRC register.
2. XOR the first eight-bit byte of the message with the low order byte of the 16-bit CRC

register, putting the result in the CRC register.

3. Shift the CRC register one bit to the right (toward the LSB), zero-filling the MSB.

Examine the LSB that was just shifted out from the register.

4. If the LSB is 0, repeat Step 3 (another shift). If the LSB is 1, EXOR the CRC register

with the polynomial value 0xA001 (1010 0000 0000 0001).

5. Repeat Steps 3 and 4 until eight shifts have been performed. When this is done, a

complete eight-bit byte will have been processed.

6. Repeat Steps 2 … 5 for the next eight-bit byte of the message. Continue doing this

until all bytes have been processed.


Result:
The final content of the CRC register is the CRC value. When the CRC is placed into the
message, its upper and lower bytes must be swapped as described in chapter 9-1
“Modbus Protocol” (CRC).

Advertising