View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Cant Figure Out Odd Problem |
Posted: Fri Sep 03, 2004 1:52 am |
|
|
Last edited by iso9001 on Sun Sep 19, 2004 8:33 pm; edited 1 time in total |
|
|
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Fri Sep 03, 2004 7:27 am |
|
|
In the drivers directory of the CCS compiler there is a file called CRC.C. It has code for 8, 16, and 32 bit CRC's... |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Fri Sep 03, 2004 10:47 am |
|
|
Last edited by iso9001 on Sun Sep 19, 2004 8:32 pm; edited 1 time in total |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Sep 03, 2004 4:04 pm |
|
|
I can recommend you to read this article, it is an extensive but easy to understand introduction to CRC and gives some example code.
CRC-codes are much more difficult than I first anticipated, for example, when people talk about a 16-bit CRC they will give you the polynome and expect this to be enough information, which it isn't!
In order to specify a CRC completely you need the following parameters:
1) Width (8, 16, 32, etc. bits wide)
2) The polynome
3) Initial value (for example X-modem and CCITT use the same polynome but different start values, resp. 0 and -1).
4) Reversed input (yes/no)? Remember, this is a serial stream, msb first or lsb first?
5) Reversed output (yes/no)?
6) Final XOR value. (Some algorithms do a final XOR)
7) Little or Big endian? (for 16 bit and higher)
In order to find out what the parameters are for your example I can recommend this site. Here is a great java applet where you can enter a sample test string and then play with all parameters until you get the expected output. |
|
|
Trampas Guest
|
CRC J1850 |
Posted: Sat Sep 04, 2004 8:40 am |
|
|
I have some code of the CRC on the J1850...
Contact me off list about the CRC and I will help.
trampas
tstern _at_ gmail.com |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Sat Sep 04, 2004 5:04 pm |
|
|
Sent you an email this morning. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Sep 05, 2004 7:16 am |
|
|
A good link to a collection of information about OBD2 (J1850, etc.)
Update:
Found a link to some freeware programs. Especially VPW is nice because in the included sourcefile vpw.c you will find an crc8 implementation. |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Sun Sep 05, 2004 8:09 am |
|
|
Opps my gmail account is:
trampas _at_ gmail.com ...
Sorry |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Sun Sep 05, 2004 1:53 pm |
|
|
Last edited by iso9001 on Sun Sep 19, 2004 8:32 pm; edited 1 time in total |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Sun Sep 05, 2004 3:05 pm |
|
|
Last edited by iso9001 on Sun Sep 19, 2004 8:31 pm; edited 1 time in total |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Sun Sep 05, 2004 5:28 pm |
|
|
Last edited by iso9001 on Sun Sep 19, 2004 8:26 pm; edited 1 time in total |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Sun Sep 05, 2004 5:34 pm |
|
|
Jordan,
This code does what you want!
Code: | typedef unsigned int8 UBYTE;
typedef unsigned int8 UINT;
typedef signed int8 INT;
typedef signed char CHAR;
typedef unsigned char UCHAR;
typedef unsigned int16 UWORD;
//typedef signed int8 BYTE;
typedef signed int16 WORD;
typedef unsigned int32 UDWORD;
typedef signed int32 DWORD;
typedef float FLOAT;
//does CRC calculations
UBYTE crc(UBYTE *data, UBYTE len)
{
UBYTE result;
UBYTE i;
UBYTE mask;
UBYTE j;
UBYTE temp;
UBYTE poly;
result=0xFF;
for(i=0; i<len; i++)
{
mask=0x80;
temp=data[i];
for(j=0; j<8; j++)
{
if(temp & mask) //bit is 1
{
poly=0x1c;
if(result & 0x80)
{
poly=1;
}
result= ((result<<1) | 0x01) ^ poly;
}else
{
poly=0;
if(result & 0x80)
{
poly=0x1D;
}
result= ((result<<1)) ^ poly;
}
mask=mask>>1;
}
}
return ~result;
}
|
Trampas |
|
|
Trampas
Joined: 04 Sep 2004 Posts: 89 Location: NC
|
|
Posted: Tue Sep 07, 2004 2:42 pm |
|
|
I forgot to sort of close this one..
ISO9001 and contacted me off the list. Apparently he is using an older version of the compiler which I think had a bug with using pointers. Thus the other code examples would not work as they used pointer indexing. Changing the code to use array indexing fixed the problem.
Trampas |
|
|
Guest
|
error |
Posted: Thu Sep 23, 2004 8:04 am |
|
|
Using this function,
there is an error: "Subscript out of range"
indicates on: temp=data[i]; |
|
|
|