Communicating with the PLC
7.2 MODBUS communication
SINAMICS V20 Converter
190 Operating Instructions, 10/2019, A5E34559884-012
Parameter upper word
Parameter lower word
Parameter upper word
Parameter lower word
Program example
The program below gives an example of calculating the CRC for MODBUS RTU.
unsigned int crc_16 (unsigned char *buffer, unsigned int length)
{
unsigned int i, j, temp_bit, temp_int, crc;
crc = 0xFFFF;
for ( i = 0; i < length; i++ )
{
temp_int = (unsigned char) *buffer++;
crc ^= temp_int;
for ( j = 0; j < 8; j++ )
{
temp_bit = crc & 0x0001;
crc >>= 1;
if ( temp_bit != 0 )
crc ^= 0xA001;
}
}
}