Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

CRC problem when using C code

Status
Not open for further replies.

john2020

Full Member level 5
Joined
Nov 13, 2005
Messages
292
Helped
12
Reputation
24
Reaction score
8
Trophy points
1,298
Activity points
4,911
CRC problem

hi all,



I have used this C code posted by others in the forum. But i found that i can only do CRC for 7 bytes. Is it the problem of only 16 elements in the feedback array? or why?


/****************************************************************************
*
* NAME: Crc8()
* PURPOSE: Generate 8-bit CRC.
*
* SYNOPSIS: unsigned char Crc8(unsigned char b, unsigned char initCrc);
*
* INTERFACE PARAMETERS:
*
* Name FG-IO Description
* ------------------- ----- -----------------------------------------
* b F I Data byte to CRC (MSBit first).
* initCrc F I Initial CRC or CRC accumulator for
* continuation.
* <return value> O CRC.
*
* DESCRIPTION:
*
* The function returns the 8-bit CRC after including "b" with the
* initial CRC "initCRC".
*
****************************************************************************/

static const UCHAR code feedback[16] =
{
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D
};

UCHAR CRC8(UCHAR b, UCHAR CRC)
{
CRC = (CRC << 4) ^ feedback[((CRC) ^ b) >> 4];
CRC = (CRC << 4) ^ feedback[((CRC >> 4) ^ b) & 0x0F];
return (CRC);
}

By the way, i hope to do CRC for 256 byte data and i just input 0xFF for the initial CRC. Is there anything wrong?


regards
john
 

moorthi

Member level 1
Joined
Aug 29, 2005
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,600
Re: CRC problem

Hi the code
CRC = (CRC << 4) ^ feedback[((CRC >> 4) ^ b) & 0x0F];

will give only one hex output and more over can you pl post the origianl code which used to calculate the CRC for 7-bytes. cos the polynomial in the calculation may be different
 

john2020

Full Member level 5
Joined
Nov 13, 2005
Messages
292
Helped
12
Reputation
24
Reaction score
8
Trophy points
1,298
Activity points
4,911
Re: CRC problem

hi moorthi

By the way, i hope to do CRC for 256 byte data and i just input 0xFF for the initial CRC.i don' t really know,whether there is any mistake in doing so?i will try to send u code for CRC for 7 bytes of data.have you tried implementing CRC-32bit or CRC-16bit?if so,tel me.

regards
john
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top