Crc Calculation - Siemens SITRANS F Operating Instructions Manual

Communication modules modbus rtu rs485
Hide thumbs Also See for SITRANS F:
Table of Contents

Advertisement

Appendix
B.6 CRC calculation
Only the internally broadcasted flow-value is checked. The expected broadcast-rate is read
at power up. If a broadcast is not received after 10 times the expected broadcast rate, the
broadcast rate is re-read from the USM (it may have been changed since power up). If the
broadcast rate was not changed (and the rate was not zero), the Run Indicator is set OFF.
Reception of ten broadcasted (flow-) values within 10 times the expected window will set the
run-indicator TRUE again.
B.6

CRC calculation

The Cyclical Redundancy Checking (CRC) field is two bytes, containing a 16–bit binary
value. The CRC value is first generated by the transmitting device, which appends the CRC
to the message. The receiving device recalculates a CRC during receipt of the message,
and compares the calculated value to the actual value it received in the CRC field. If the two
values are not equal an error results.
In the following a short text description of how the CRC is calculated is provided. This
description is then followed by a C programming example.
CRC calculation
1. Load a 16–bit register with FFFF hex (all 1's). Call this the CRC register.
2. Exclusive OR the first 8–bit byte of the message with the low–order byte of the 16–bit
3. Shift the CRC register one bit to the right (toward the LSB), zero–filling the MSB. Extract
4. (If the LSB was 0): Repeat Step 3 (another shift). (If the LSB was 1): Exclusive OR the
5. Repeat Steps 3 and 4 until 8 shifts have been performed. When this is done, a complete
6. processed.
7. Repeat Steps 2 through 5 for the next 8–bit byte of the message. Continue doing this until
8. The final content of the CRC register is the CRC value.
9. When the CRC is placed into the message, its upper and lower bytes must be swapped
Placing the CRC into the Message
When the 16–bit CRC (two 8–bit bytes) is transmitted in the message, the low-order byte will
be transmitted first, followed by the high-order byte.
For example, if the CRC value is 1241 hex (0001 0010 0100 0001):
Addr
Func
68
CRC register, putting the result in the CRC register.
and examine the LSB.
CRC register with the polynomial value 0xA001 (1010 0000 0000 0001).
8–bit byte will have been
all bytes have been processed.
as described below.
Data count
Data n
Data n+1
Data n+2
Operating Instructions, 06/2010, A5E00753974-04
Data n+x
CRC LO
0x41
Modbus RTU RS485
CRC HI
0x12

Advertisement

Table of Contents
loading

Table of Contents