Crc16 (cyclic redundancy check) – Rockwell Automation 1403-NSC Smart Communication Card Instruction Sheet User Manual

Page 48

Advertising
background image

C–4

Serial Communication Protocol Tutorial

Publication 1403-5.1

CRC16 (Cyclic Redundancy Check)

The 16-bit cyclic redundancy check (CRC16) is a method
to check the integrity of a message packet. CRC16
provides a higher level of data security than block check
character.

Calculate the CRC value for master messages using the
value of the STN, STX, data bytes, and the ETX (do not
add in the associated DLE for STX and ETX). Calculate
the CRC value for slave messages the same way, except
DO NOT include the STX byte in the CRC calculation.

Important:

To transmit the STN or data value of 10
hex, you must use the data symbol DLE
DLE. However, only one of these DLE
data bytes is included in the CRC value.

At the start of a message packet, the transmitter clears a
16-bit register for the CRC value. As the first byte is
transmitted, it is Exclusive-Or’ed (least significant bit to
the right) with the right eight bits of the CRC register.
The result is placed back into the right eight bits of the
CRC register.

The CRC register is then shifted right eight times by
inserting 0x on the left. Each time a 1 is shifted out on
the right, the CRC register is Exclusive-OR’ed with the
following 16-bit binary constant:

CONSTANT = 1010 0000 0000 0001

The result is placed back into the CRC register. After
this shifting is completed, you are ready to transmit the
next byte.

As each additional byte is transmitted, it is included in
the value in the CRC register the same way. After the
ETX value is included in the value in the register and is
transmitted, the value in the CRC register is transmitted
(right bit first) as the CRC field.

The receiver also calculates the CRC value and compares
it to the received CRC value to verify the accuracy of the
data received.

The following structured English procedure shows the
steps involved in determining the CRC16 value.

data_byte = STN, STX, all application layer data, ETX
CLEAR CRC_REGISTER
For each data_byte

Get data_byte
XOR (data_byte, right 8 bits of CRC_REGISTER)
PLACE RESULT in right 8 bits of CRC_REGISTER
DO 8 times

Shift bit right, shift in 0 at left
IF bit shifted = 1

XOR (CONSTANT, CRC_REGISTER)
PLACE RESULT in CRC_REGISTER

END IF

END DO

END FOR
TRANSMIT CRC_REGISTER as 2 byte CRC field

Examples

Example Destination Address = 123 (0x78)

Example Source Address = 0 (0x00)

Write

Device Configuration Data Table (Table 1 of Data
Tables)

Size = 44 words (88 bytes = 0x58)

Advertising