Crc Computation; Definition; Usage - DAE INSTRUMENT CC1000a06 Reference

Smart lighting control system modbus gateway
Table of Contents

Advertisement

CRC Computation

CRC Computation
The CC1000 conforms to the Modbus/RTU protocol and thus uses CRC16 for its error checking. The computed CRC is
appended to the end of the message with the LSB first and then the MSB. Below is the pseudo code for computing the
CRC as used by the standard Modbus/RTU. The pseudo code is written in the Ruby language and can be directly used
as such.
Definition
def get_crc (*byte_array)
sum = 0xFFFF
byte_array.each do |byte|
sum ^= byte
8.times do
carry = (1 == sum & 1)
sum = 0x7FFF & (sum >> 1)
sum ^= 0xA001 if carry
end
end
return [sum & 0xFF, sum >> 8]
end

Usage

>> crc = get_crc(1,3,0,141,0,5)
=> [21, 226]
CC1000 Modbus Reference 2.10e!
<---- [CRC low byte, CRC high byte]
44/122

Advertisement

Table of Contents
loading

Table of Contents