Searching \ for ' help with CRC-16 with Xmodem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/method/errors.htm?key=crc
Search entire site for: 'help with CRC-16 with Xmodem'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] help with CRC-16 with Xmodem'
2001\07\11@105651 by Oluseyi Odeinde

flavicon
picon face
Hello,

I'm writing an Xmodem implementation (sending mode only). The code is
complete. However, when run no data is received at the other end. I've
narrowed the problem down to my CRC-16 implementation. These are the
functions in question:

/******GLOBAL VARIABLES*******/
unsigned int totalCrc;     // Tx CRC
char CrcLowByte;           // Storage for CRC
char CrcHighByte;
/*****************************/

void ClearCrc(void)
{
totalCrc=0;
CrcHighByte = 0;
CrcLowByte = 0;
}

// Add next character to the CRC checksum for Xmodem packets
unsigned int calc(unsigned int c) {
  char i;                // Just a loop index
  c &= 0xFF;             // Only calculate CRC on low byte
  for (i=0;i<8;i++) {    // Loop eight times, once for each bit
     if (c&1) {          // Is bit high?
        c >>= 1;          // Position for next bit
        c ^= 0x1021;     // Toggle the feedback bits
     } else c >>= 1;      // Just position for next bit
  }
 return c;               // Return the 16 bit checksum
}

// Update CRC with new char
void UpdateCrc(unsigned char c) {
  totalCrc = calc((unsigned int)c^totalCrc) ^ (totalCrc/256); // Add CRC
from this char to running total
}

void FinishCrc(void)
{
  totalCrc=(totalCrc & 0xFFFF);
  CrcHighByte = (*((unsigned char*)&crc +1));
  CrcLowByte =  ((unsigned char)crc);
}

and they are called within the main program code as follows:

main(void){
   ...........
   ..........
   ClearCrc();
   for (i=0;i<buffer1_size){
       UpdateCrc(xmodem_buffer1[i]);
   }
   for (i=0;i<buffer2_size){
       UpdateCrc(xmodem_buffer2[i]);
   }
   FinishCrc();
  ..........
  ..........
}

I would be extremely grateful if anyone can tell me what is wrong with the
above implemention. I've combed through the above code several times but
still fail to see where the problem lies. any suggestions will be welcomed.

TIA
seyi

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\11@110704 by Oluseyi Odeinde

flavicon
picon face
Hello,

I'm writing an Xmodem implementation (sending mode only). The code is
complete. However, when run no data is received at the other end. I've
narrowed the problem down to my CRC-16 implementation. These are the
functions in question:

/******GLOBAL VARIABLES*******/
unsigned int totalCrc;     // Tx CRC
char CrcLowByte;           // Storage for CRC
char CrcHighByte;
/*****************************/

void ClearCrc(void)
{
totalCrc=0;
CrcHighByte = 0;
CrcLowByte = 0;
}

// Add next character to the CRC checksum for Xmodem packets
unsigned int calc(unsigned int c) {
  char i;                // Just a loop index
  c &= 0xFF;             // Only calculate CRC on low byte
  for (i=0;i<8;i++) {    // Loop eight times, once for each bit
     if (c&1) {          // Is bit high?
        c >>= 1;          // Position for next bit
        c ^= 0x1021;     // Toggle the feedback bits
     } else c >>= 1;      // Just position for next bit
  }
 return c;               // Return the 16 bit checksum
}

// Update CRC with new char
void UpdateCrc(unsigned char c) {
  totalCrc = calc((unsigned int)c^totalCrc) ^ (totalCrc/256); // Add
CRC from this char to running total
}

void FinishCrc(void)
{
  totalCrc=(totalCrc & 0xFFFF);
  CrcHighByte = (*((unsigned char*)&crc +1));
  CrcLowByte =  ((unsigned char)crc);
}

and they are called within the main program code as follows:

main(void){
   ...........
   ..........
   ClearCrc();
   for (i=0;i<buffer1_size){
       UpdateCrc(xmodem_buffer1[i]);
   }
   for (i=0;i<buffer2_size){
       UpdateCrc(xmodem_buffer2[i]);
   }
   FinishCrc();
  ..........
  ..........
}

I would be extremely grateful if anyone can tell me what is wrong with
the above implemention. I've combed through the above code several times
but still fail to see where the problem lies. any suggestions will be
welcomed.

TIA
seyi

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\11@125836 by Bob Barr

picon face
Oluseyi Odeinde wrote:

>
>main(void){
>     ...........
>     ..........
>     ClearCrc();
>     for (i=0;i<buffer1_size){
>         UpdateCrc(xmodem_buffer1[i]);
>     }

This may be an error introduced when you copied the code to the email, but
without an 'i++' in this for loop, it will never terminate. (The second for
loop wouldn't terminate either for the same reason.)

Does your program run to completion?

Regards, Bob
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\11@212220 by Oluseyi Odeinde

flavicon
picon face
Bob,

yes, that was a typo. the program does run to completion in the sense that it
times out but without any data received at the other end. however, i should
mention that the program works smoothly if xmodem is run in checksum mode as
opposed to CRC mode hence my saying earlier that the problem has been narrowed
down to my crc implementation.

cheers
seyi

Bob Barr wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\12@042555 by dr. Imre Bartfai

flavicon
face
Hi,

I have implemented a CRC16 and it works. However, I definitely separate
the input and output field; this may be your problem in function
'calc'. If u need, I can send my implementation.

I hope this helps.

Regards,
Imre


On Wed, 11 Jul 2001, Oluseyi Odeinde wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\07\12@092034 by Paul Hutchinson

flavicon
face
The problem might be execution time to calculate the CRC. In my experience
"C" code is usually too slow to calculate CRC's and keep-up with the serial
data rate. For speed reasons, I've used a look-up table or, embedded
assembly code to do the calculations on various processors.

Have you used a serial data analyzer to see what data is being sent?

Paul

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...