View previous topic :: View next topic |
Author |
Message |
horizontech
Joined: 09 Nov 2003 Posts: 13
|
FCS Frame Check Sequence help ! |
Posted: Tue Jun 01, 2004 5:31 pm |
|
|
Hi !
I need to send 12 bytes true rs232 with 2 extra byte as FCS frame check
i looking for example to understand how to compute the 2 FCS bytes ?
I have read the string on other transmiter :
255 255 000 008 000 034 000 000 000 002 001 255 176 038
255 255 000 008 000 034 000 000 000 002 002 255 173 040
the last 2 bytes on each example is FCS !
Thank you very munch for all your help !
Alain Tanguay |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jun 01, 2004 5:45 pm |
|
|
It seems you are using HDLC, correct? This is how I calculated fcs in a project long time ago...
Code: |
unsigned int check (char *frame, int nbytes)
{
unsigned char ch;
unsigned bit, fcs;
int i, j;
/*
* Initialize the fcs.
*/
fcs = 0xFFFF;
/*
* Look at each character in the frame.
*/
for (i = 0; i < nbytes; ++i)
{
ch = frame [i];
fcs ^= ch;
/*
* Look at the LSB of the fcs 8 times.
*/
for (j = 0; j < 8; ++j)
{
bit = fcs % 2;
fcs >>= 1;
/*
* Now, do an exclusive-OR between this bit and bits 3, 10, and 15 of the
* fcs, without disturbing the other bits.
*/
if (bit) fcs ^= 0x8408;
}
}
/*
* Lastly, take the ones complement of the fcs.
*/
fcs = ~fcs;
return (fcs);
}
|
|
|
|
horizontech
Joined: 09 Nov 2003 Posts: 13
|
FCS Frame Check Sequence help ! |
Posted: Wed Jun 02, 2004 6:15 pm |
|
|
Thanks for info
I looking for a step by step calculation for understand how is work ?
Thanks for your time
Alain tanguay |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Wed Jun 02, 2004 8:11 pm |
|
|
I think the comments in the code are pretty intuitive, I can't give you any more information than it's already there
Bear in mind that what I posted is the FCS algorithm for HDLC. Yours might be different. Does it return the same result as you are expecting? |
|
|
|