CRC16-CITT - Xmodem implement

Hello guys,
i have problem with CRC16 Xmodem.

When i take a part of the code from serial string {FC0100}, how can i calculated the CRC?


Which Windows program sends that string and where is the string documented? It is extremely unusual that the CRC is at the beginning of the string. Are you sure you have this right?


I’ve figured out how to get the CRC.
Of the example data given:

  • the last 6 characters are each one ASCII character.
  • the F5F1 is two characters 0xF5 and 0xF1.
    The CRC uses the xmodem CRC polynomial but the initial value is zero - xmodem protocol CRC uses an initial value of 0xFFFF.

This code uses the example data above to calculate its CRC. You’ll have to extract the CRC code and add it to your sketch.

// This uses CRC16-CCITT
// From:,96539.0.html

// This data is from
char CRC1 [6] = {
  // CRC is 0xF5F1

void setup(void)
  uint16_t crc_out;

  crc_out = calc_crc(CRC1,6); //Calculate CRC on-the-fly

void loop(void)

uint16_t calc_crc(char *msg,int n)
  // Initial value. xmodem uses 0xFFFF but this example
  // requires an initial value of zero.
  uint16_t x = 0;

  while(n--) {
    x = crc_xmodem_update(x, (uint16_t)*msg++);

// See bottom of this page:
// Polynomial: x^16 + x^12 + x^5 + 1 (0x1021)
uint16_t crc_xmodem_update (uint16_t crc, uint8_t data)
  int i;

  crc = crc ^ ((uint16_t)data << 8);
  for (i=0; i<8; i++) {
    if (crc & 0x8000)
      crc = (crc << 1) ^ 0x1021; //(polynomial = 0x1021)
      crc <<= 1;
  return crc;


It works, thank you very well :slight_smile: