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 > > 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: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics