Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

#### Computing CRC for DNP3

In DNP3 (Distributed Network Protocol 3), the cyclic redundancy check (CRC) is used for error
detection and ensuring the integrity of data frames. The CRC calculation in DNP3 follows a specific
algorithm to generate a checksum that can be verified by the receiving end. Below is a step-by-step
guide to computing the CRC for DNP3.

**1. Frame Preparation**

- Before computing the CRC, it's important to ensure that the data frame is organized and
formatted according to the DNP3 protocol specifications. This includes arranging the frame fields
such as start and stop flags, address field, control field, and information field in the correct order.

**2. CRC Initialization**

- Initialize the CRC register to a predefined starting value. In DNP3, the initial value for CRC
computation is typically 0xFFFF (hexadecimal).

**3. Processing the Data**

- Iterate through the information field of the data frame, processing each byte of data in sequence.
Perform bitwise XOR operations and shift operations on the CRC register based on the current byte
being processed.

**4. Finalization**

- After processing all the bytes in the information field, the CRC register holds the computed CRC
value. This value needs to be finalized before inclusion in the data frame. This often involves
complementing the CRC value or performing additional bitwise operations to ensure consistency
with the DNP3 CRC specification.

**5. Incorporating the CRC**

- Once the CRC value has been computed and finalized, it is added to the data frame in the
designated CRC field. The CRC field is typically located at the end of the data frame and is####
Computing CRC for DNP3 HDLC Frames
This document provides an overview of how CRC (Cyclic Redundancy Check) is calculated for
DNP3 HDLC (High-Level Data Link Control) data frames to ensure error detection and frame
integrity.

**CRC Polynomial**

The CRC polynomial used for DNP3 is CRC-16-CCITT, which is a 16-bit polynomial of x16 + x12 + x5
+ 1. This polynomial was chosen because it performs well for error detection.

**Preparing the Frame**

Before calculating the CRC, the entire frame excluding the CRC field is preprocessed. All bits are
reversed, with the MSB of each byte moved to the LSB position and vice versa. This process is
known as bit stuffing.

**Initialization**

The CRC register is initialized to all 1s (FFFF hex). This initial value is commonly referred to as the
CRC preload value.

**Calculation**

The CRC calculation is performed by dividing the preprocessed frame by the CRC polynomial using
modulo-2 division. This is done by treating the frame as a binary number and polling out bits that
correspond to the polynomial.

If the current CRC bit being examined is a 1, the CRC register is XORed with the polynomial. Bit
shifting and examination continues until all frame bits are processed.

**Final CRC Value**


After processing the entire frame, the remaining value in the CRC register is the CRC checksum.
This 16-bit CRC value is appended to the end of the frame in the CRC field.

The receiving device performs the same CRC calculation on the received frame. If the calculated
CRC matches the value in the frame, then no errors were detected during transmission.

This process ensures high reliability of DNP3 HDLC frames through robust error detection using the
CRC technique as per standard protocol specifications.

You might also like