#include <msp430g2553.h>
#include <string.h>
#include <stdio.h>
/*
* main.c
*/
unsigned char byte_to_crc[];
unsigned short crc;
unsigned int len;
unsigned int pos;
unsigned int i;
unsigned short mod_rtu_crc(char byte_to_crc[], int len); // generate crc
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
byte_to_crc[0] = 0x01;
byte_to_crc[1] = 0x03;
byte_to_crc[2] = 0x00;
byte_to_crc[3] = 0xFA;
byte_to_crc[4] = 0x00;
byte_to_crc[5] = 0x04;
// should give 0x6438 as crc
mod_rtu_crc(byte_to_crc[] , 6);
//return 0;
}
unsigned short mod_rtu_crc(char byte_to_crc[], int len)
{
crc = 0xFFFF;
for(int pos = len; pos > 0; pos--){
crc ^= (unsigned short)byte_to_crc[pos-1]; // XOR byte into least sig. byte of crc
for(int i = 8; i != 0; i--){ // Loop over each bit
if((crc & 0x0001) != 0){ // If the LSB is set
crc >>= 1; // Shift right and XOR 0xA001
crc ^= 0xA001;
}
else{ // Else LSB is not set
crc >>= 1; // Just shift right
}
}
// Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes)
}
return crc;
}
Hi, I am very new to embedded coding and I am trying to implement a CRC to modbus frame currently. So I need to test CRC function as a single module for now. And I failed it as you see, at line 29, 38 and 41, I am getting #29 expected an expression error. If you could help me a little I would be very pleased. Thanks.