The Amulet CRC Communication Protocol uses a 16-bit CRC (Cyclic Redundancy Check) to ensure data integrity. Each message sent is comprised of a slave ID, an Amulet opcode, a variable number of bytes within the message payload, and finally the two bytes of the CRC. The slave ID, Amulet opcode, and all the bytes of the message payload are run through the CRC algorithm. The resulting 16-bit CRC is appended to the end of every message. The Least Significant Byte of the CRC is sent first, followed by the Most Significant Byte of the CRC.
When receiving a packet of information from the Amulet module, the calculated CRC should match the last two bytes of the packet. If not, then the packet should be disregarded as the integrity of the data cannot be assured.
For example, a master message from the Amulet chip requesting the value of byte variable # 5 would look like this:
0x02 0x20 0x05 0x09 0xC3
Where:
0x02 - Host Processor slave ID
0x20 - Request byte variable (Amulet opcode)
0x05 - Byte variable index #5
0x09 - CRC LSByte
0xC3 - CRC MSByte
Running 0x02 0x20 0x05 through the CRC algorithm results in the 16-bit number 0xC309
Code for the CRC algorithm:
#define CRC_SEED 0xFFFF
#define CRC_POLY 0xA001
int calcCRC(char *ptr, int count)
{
unsigned short crc = CRC_SEED; // initialize CRC
int i;
while (count-- > 0)
{
crc = crc ^ *ptr++;
for (i=8; i>0; i--)
{
if (crc & 0x0001)
crc = (crc >> 1) ^ CRC_POLY;
else
crc >>= 1;
}
}
return crc;
}

Start Here
Development Tools
| Site Use Terms | Terms of Sale | Privacy | Warranty | Site Map | |