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: > 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 UpdateCrc(xmodem_buffer1[i]); > } > for (i=0;i 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 > > > -- 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