Hello Noodle7,
I am also looking for 8-bit CRC.
How to generate the look up table, that you have used in the code given.
thank you.
Regards
Sunil
Hello:
Attached you´ll find the examples that we used to develop the CRC. I hope this will be helpfull for you.
EM
/* calculates 16-bit CRC of given data *//* based on the polynomial x^16+x^15+x^2+1 */unsigned int calc_crc_core(unsigned int *start,unsigned int *end) { unsigned int crc=0,c; int i; while (start<=end) { c=*start; for(i=0;i<16;i++) { if((crc ^ c) & 1) crc=(crc>>1)^0xA001; else crc>>=1; c>>=1; } start++; } return(crc);}
Message Edited by Alban on 05-11-2006 10:32 AM
Hello:
Starting with your code, please, let me know if my code would be o.k.
/* calculates 8-bit CRC of given data */
/* based on the polynomial X^8 + X^5 + X^4 + 1 */
unsigned int calc_crc_core(unsigned int *start,unsigned int *end) {
unsigned int crc=0,c;
int i;
while (start<=end) {
c=*start;
for(i=0;i<8;i++) {
if((crc ^ c) & 1) crc=(crc>>1)^0x8c;
else crc>>=1;
c>>=1;
}
start++;
}
return(crc);
}
Regards
Eneko
Hello Eneko,
I think you will need to change all references to unsigned int type to read unsigned char (including the function parameters).
Rather than calculating the CRC from a data table, for some applications it may be useful to update the CRC value "on the fly", perhaps within a SCI interrupt routine. The following code is intended to do this, but has not been tested. Of course, the function does not initialise crc value. It should be feasible to use the same function for both sending and receiving serial data packets.
/* Update 8-bit CRC value
using polynomial X^8 + X^5 + X^4 + 1 */
#define POLYVAL 0x8C
void update_crc(unsigned char new, unsigned char *crc)
{
unsigned char c, i;
c = *crc;
for (i = 0; i < 8; i++) {
if ((c ^ new) & 1) c = (c >> 1 ) ^ POLYVAL;
else c >>= 1;
new >>= 1;
}
*crc = c;
}
Regards,
Mac
Message Edited by bigmac on 05-14-200612:58 AM
Message Edited by bigmac on 2007-02-1206:02 PM
Hello Eniko,
It should be relatively easy to adapt the code supplied by UK_CF_FAE for other polynomials, including 8-bit. Do you know which polynomial you wish to use for your application?
The method shown will consume much less code space than the look-up table method, but will require longer execution time.
Regards,
Mac
Hi Mac:
I have choosen a standar one. X^8 + X^5 + X^4 + 1 . Can you tell me how can I built my CRC code 8 bit ?
Thanks in advance.
Eneko