Other Parts Discussed in Thread: MSP430FR2355
Hello Team,
Actually i'm trying to understand CRC16 examle code implemented in msp430FR2355 and i'm confused.
no online calculated CRC16-CCITT is matching with results obtained from CRC module(CRCDIRB) for example i'm sending string "BVK" getting CRC=27860, but online CRC16 calculators giving result 0xE2E7.
I tried to send "BVK" + CRC to CRC module(CRCDIRB) to get 0 result but i'm getting something else. If i check with online CRC16 calculator with 0xE2E7 i'm getting 0 as expected. Can't understand where the things going wrong.
So, with CRC module how to check the CRC correctness? any help would be very thankfull.
Below is the code and i have tried by CRC_Str[]="BVK";
#include <msp430.h>
unsigned int CRC_Init = 0xFFFF;
unsigned int i;
unsigned int CRC_Str[]= {0x0fc0, 0x1096, 0x5042, 0x0010, // 16 random 16-bit numbers
0x7ff7, 0xf86a, 0xb58e, 0x7651, // these numbers can be
0x8b88, 0x0679, 0x0123, 0x9599, // modified if desired
0xc58c, 0xd1e2, 0xe144, 0xb691 };
unsigned int CRC_Results;
unsigned int SW_Results;
unsigned int CRC_New;
// Software Algorithm Function Definition
unsigned int CCITT_Update(unsigned int, unsigned int);
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1OUT &= ~BIT0; // Clear P1.0 output state
P1DIR |= BIT0; // Set P1.0 to output direction
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
// Init CRC
CRCINIRES = CRC_Init; // Init CRC with 0xFFFF
for(i=0;i<16;i++)
{
// Input random values into CRC Hardware
CRCDIRB = CRC_Str[i]; // Input data in CRC
__no_operation();
}
CRC_Results = CRCINIRES; // Save results (per CRC-CCITT standard)
CRC_New = CRC_Init; // Put CRC Init value into CRC_New
for(i = 0; i < 16; i++)
{
// Input values into Software algorithm (requires 8-bit inputs)
// Clear upper 8 bits to get lower byte
unsigned int LowByte = (CRC_Str[i] & 0x00FF);
// Shift right 8 bits to get upper byte
unsigned int UpByte = (CRC_Str[i] >> 8);
// First input lower byte
CRC_New = CCITT_Update(CRC_New,LowByte);
// Then input upper byte
CRC_New = CCITT_Update(CRC_New,UpByte);
}
SW_Results = CRC_New;
// Compare data output results
if(CRC_Results==SW_Results) // if data is equal
P1OUT |= BIT0; // set the LED
else
P1OUT &= ~BIT0; // if not, clear LED
while(1); // infinite loop
}
// Software algorithm - CCITT CRC16 code
unsigned int CCITT_Update(unsigned int init, unsigned int input)
{
unsigned int CCITT;
CCITT =(unsigned char)(init >> 8)|(init << 8);
CCITT ^= input;
CCITT ^= (unsigned char)(CCITT & 0xFF) >> 4;
CCITT ^= (CCITT << 8) << 4;
CCITT ^= ((CCITT & 0xFF) << 4) << 1;
return CCITT;
}