
14
CRC check code: the error check (CRC) field takes up two bytes and contains a 16 bit binary
value. The CRC value is calculated by the transmitting device, and then attached to the data frame.
The receiving device recalculates the CRC value when receiving byte data, and then compares it
with the value in the received CRC field. If the two values are not equal, an error occurs.
The process of generating a CRC is as follows:
1) Reset a 16-bit register as 0xFFFF (all 1), which is called CRC register.
2) The 8-bit of the first byte in the data frame is XOR with the low byte in CRC register, and
the result is saved back to CRC register.
3) Move the CRC register to the right by one bit, fill the highest bit with 0, and the lowest bit
is out and detected.
4) If the lowest bit is 0, repeat the third step (the next shift); if the lowest bit is 1, XOR the
CRC register with a preset fixed value (0xa001).
5) Repeat the third and fourth steps until eight shifts, this completes a complete octet.
6) Repeat steps 2 through 5 to process the next octet until all bytes are processed.
7) The final CRC register value is the value of the CRC.
In addition, there is a method to calculate CRC by using the preset table. Its main feature is that
the calculation speed is fast, but the table needs a large storage space. This method will not be
described here, please refer to the related materials.
8.2 Introduction to function code
8.2.1 Function code 03H or 04H: register read
This function allows users to obtain data and system parameters collected and recorded by the
device. There is no limit to how much data a host can request at a time, but it cannot exceed the
defined address range.
The following example reads a value from machine 01 at the address 0008H.
Master Send
Data
Slave Return
Data
Address
01H
Address
01H
Function
03H
Function
03H
Start Address
High byte
00H
Bytes
02H
Low byte
08H
Data of
Registers
High byte
00H
number of
Registers
High byte
00H
Low byte
50H
Low byte
01H
CRC codes
Low byte
21H
CRC codes
Low byte
74H
High byte
75H
High byte
0CH
7.2.2 Function code 10H: write register
Function code 10H allows the user to change the contents of multiple registers. The time and
date in the meter can be written with this function number. The master can write up to 16 (32 bytes)
of data at a time.
The following example is a device with a preset address of 01 date and time of 12:00 on Friday,
December 01, 2009.From Monday to Sunday, 1 to 7 are used instead.