Chapter 7 Specifications and Characters
- 119 -
CRC register moves one bit to right, then run XOR calculation with A001
H
;
Step 4: Go to step 5 till the third step has been executed for 8 times, otherwise return to step 3.
Step 5: Repeat the steps from 2 to 4 for the next bit of instruction information, the comment of CRC
register is the CRC error detection value while all the bits have been executed by the same way.
Note: After calculating out the CRC error detection value, the CRC low bit should be filled first in
instruction information, and then fill the high bit of CRC.
Please refer to the following example:
Read 2 words from the 0101
H
address of 01
H
servo. The final CRC register content calculated from ADR
to the last bit of data is 3794
H
, and then the instruction information is shown as follows,
Please be sure that 94
H
is transmitted before 37
H
.
End1
End1
End1
End1
、
End0
End0
End0
End0
(
Communication
Communication
Communication
Communication is
is
is
is complete.
complete.
complete.
complete.
)
ASCII
ASCII
ASCII
ASCII mode
mode
mode
mode
:
Communication is end with (0D
H
) namely character‘\r’
『
carriage return
』
and (0A
H
) namely character‘\n’
『
new line
』
.
RTU
RTU
RTU
RTU mode
mode
mode
mode
:
When the time exceeds the sleep interval of at least 4 bytes transmission time in current communication
speed means the communication is finished.
Example
Example
Example
Example
:
The following example uses C language to generate CRC value. The function needs two parameters.
unsigned char * data;
unsigned char length;
The function will return unsigned integer type CRC value.
unsigned int crc_chk(unsigned char * data,unsigned char length){
int i,j;
unsigned int crc_reg=oxFFFF;
While(length- -){
crc_ reg ^=*data++;
for(j=0;j<8;j++){
If(crc_reg & 0x01){
crc_reg=( crc_reg >>1)^0xA001;
}else{
crc_reg
=
crc_reg >>1;
}
}
}
return crc_reg;
}
ADR
01
H
CMD
03
H
Data start address
01
H
(high-bit)
01
H
(low-bit)
Data number
(
count as word
)
00
H
(high-bit)
02
H
(low-bit)
CRC checking
94
H
(low-bit)
CRC checking
37
H
(high-bit)