Specifications

54
5.7.2.2 CRC-4 checksum computation
The CRC-4 is a cyclic redundancy check, where the 4 indicates the number of bits in the CRC
checksum. Every message m can be considered as a string of n bits b
j
:
m = b
n1
b
n2
b
n3
… b
1
b
0
(5.7.1)
where every b
j
is either 0 or 1. To this message m we add four bits that are zero:
m’ = b
n1
b
n2
b
n3
… b
1
b
0
0 0 0 0 (5.7.2)
This bit string can be interpreted as a binary polynomial:
m’(x) = b
n1
x
n+3
+ b
n2
x
n+2
+ b
n3
x
n+1
+ … b
1
x
5
+ b
0
x
4
(5.7.3)
Now the remainder r(x) is determined of m’(x) divided by a special polynomial, the CRC
generator, c(x):
c(x) = x
4
+ x + 1 (5.7.4)
The polynomial r(x) will have four binary coefficients:
r(x) = r
3
x
3
+ r
2
x
2
+ r
1
x + r
0
(5.7.5)
and these are substituted for the zeros at the end of message m’:
m” = b
n1
b
n2
b
n3
… b
1
b
0
r
3
r
2
r
1
r
0
(5.7.6)
Consequently, m”(x) mod c(x) = 0.
The Datawell messages include a 4-bit message ID; when transmitted the order of bits is
changed to:
m(3) = b
n1
b
n2
b
n3
b
n4
r
3
r
2
r
1
r
0
b
n5
… b
1
b
0
(5.7.7)
or, in words, the fist byte of the transmitted message consists of one nibble for the MsgID, and
one nibble for the CRC-4 checksum; the rest of the message is the data bytes. After reception,
the message is rearranged by moving the second nibble to the end; the resulting bit string is
divided by c(x) and, if the remainder is zero, the message is considered correct.
For clarity the listing of a CRC-4 checksum c-routine is given in Figure 5.7.1.