Yaskawa F7 Drive User Manual User Manual
Page 226

Communications D - 7
Typical CRC-16 Calculation Program in Quick Basic
crcsum# = &HFFFF&
crcshift# = &H0&
crcconst# = &HA001&
CLS
PRINT ”*********************************************”
PRINT
PRINT “ CRC-16 Calculator “
PRINT
PRINT ”*********************************************”
PRINT “If entering data in hex, precede the data with ‘&H’”
PRINT “ Example: 32decimal = 20hex = &H20”
PRINT ”*********************************************”
PRINT
INPUT “Enter the number of bytes in the message: “, maxbyte
FOR bytenum = 1 TO maxbyte STEP 1
PRINT “Enter byte “; bytenum; “:”:
INPUT byte&
byte& = byte& AND &HFF&
crcsum# = (crcsum# XOR byte7) AND &HFFFF&
FOR shift = 1 TO 8 STEP 1
crcshift# = (INT(crcsum# / 2)) AND &H7FFF&
IF crcsum# AND &H1& THEN
crcsum# = crcshift# XOR crcconst#
ELSE
crcsum# = crcshift#
END IF
NEXT shift
NEXT bytenum
lower& = crcsum# AND &HFF&
upper& = (INT(crcsum# / 256)) AND &HFF&
PRINT “Lower byte (1st) = “, HEX$(lower&)
PRINT “Upper byte (2nd) = “, HEX$(upper&)
Typical CRC-16 Calculation Program in C
// *buf pointer to character array that contains the characters used to calculate CRC
// bufLen number of characters to calculate CRC for
// *crc pointer to the array that contains the calculated CRC
void getMBCRC(cahr *buf, int bufLen, char *crc) {
unsigned long crc_0 = 0xffff; // Declare and initialize variables
unsigned long crc_1 = 0x0000;
int i,j;
for (i=0; i
for (j=0;j<8;j++){ // Loop through character bits
crc_1 = (crc_0 >> 1) & 0x7fff; // Shift result right one place and store
if (crc_0 & 0x0001) // if pre-shifted value bit 0 is set
crc_0 = (crc_1 ^ 0xa001); // XOR the shifted value with 0xa001
else // if pre-shifted value bit 0 is not set
crc_0 = crc_1; // set the pre-shifted value equal to the shifted value
}
}
crc[0] = (unsigned char)((crc_0/256) & 0x00ff); // Hi byte
crc[1] = (unsigned char)((crc_0 & 0x00ff); // Lo byte
return;
}
No Response Message
The Drive disregards the command message and does not return the response message in the following cases:
1. In simultaneous broadcasting of data (slave address field is 0), all slaves execute but do not respond.
2. When a communication error (overrun, framing, parity, or CRC-16) is detected in the command message.
3. When the slave address in the command message does not coincide with the address set in the slave.
4. When the command message data length is not proper.