08 November 2019 1 3K Report

I want to implement CRC-16/X-25. I have a code written in C for CRC-16/CCITT_FALSE, but I don't know what changes do I need to make in that code for CRC-16/X-25 implementation?

The code I am using for CRC-16/CCITT-FALSE is given below:

#include #define CRC_POLYNOMIAL 0x1021 #define USHORT_TOPBIT 0x8000 short crc_ret; // function initialisation unsigned short crc16(const char *buf, unsigned int buf_len) { unsigned short ret = 0xFFFF; // Initial Value int bit = 8; do { if (!buf) { break; } unsigned int i = 0; for (i=0; i> 8)); for (bit = 8; bit > 0; --bit) { if (ret & USHORT_TOPBIT) ret = (unsigned short)((ret >> 1) ^ CRC_POLYNOMIAL); else ret = (unsigned short)(ret >> 1); } } } while (0); return ret; } int main(void) { PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode to activate // previously configured port settings char buf[16]; buf[0] = 0x5A; //buf[0], buf[1] and buf[2] are data bytes buf[1] = 0xCF; buf[2] = 0x00; crc_ret = crc16(buf, 3); // Calling CRC function }

Any help would be highly appreciated

More Raza Javed's questions See All
Similar questions and discussions