CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Cant Figure Out Odd Problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

Cant Figure Out Odd Problem
PostPosted: Fri Sep 03, 2004 1:52 am     Reply with quote

Question

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

View user's profile Send private message

PostPosted: Fri Sep 03, 2004 7:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 03, 2004 10:47 am     Reply with quote

Question

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

View user's profile Send private message

PostPosted: Fri Sep 03, 2004 4:04 pm     Reply with quote

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
PostPosted: Sat Sep 04, 2004 8:40 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 04, 2004 5:04 pm     Reply with quote

Sent you an email this morning.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 05, 2004 7:16 am     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Sun Sep 05, 2004 8:09 am     Reply with quote

Opps my gmail account is:

trampas _at_ gmail.com ...

Sorry
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Sun Sep 05, 2004 1:53 pm     Reply with quote

Question

Last edited by iso9001 on Sun Sep 19, 2004 8:32 pm; edited 1 time in total
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Sun Sep 05, 2004 3:05 pm     Reply with quote

Question

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

View user's profile Send private message MSN Messenger

PostPosted: Sun Sep 05, 2004 3:57 pm     Reply with quote

Check out this site:

http://obddiagnostics.com/obdinfo/CRC.txt

I have verified this code works.

Trampas
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Sun Sep 05, 2004 5:28 pm     Reply with quote

Question

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

View user's profile Send private message MSN Messenger

PostPosted: Sun Sep 05, 2004 5:34 pm     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Tue Sep 07, 2004 2:42 pm     Reply with quote

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
PostPosted: Thu Sep 23, 2004 8:04 am     Reply with quote

Using this function,
there is an error: "Subscript out of range"
indicates on: temp=data[i];
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group