Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus CRC-16 used instead us regular CRC-16 on TX of messages coming for Jeenodes #3

Closed
paularmand opened this issue Sep 30, 2013 · 1 comment

Comments

@paularmand
Copy link

On receive the regular CRC-16 of the jeenodes is correctly calculated on the FLM side, but on transmit a different modbus CRC-16 is used to transmit the messages back to the Jeenodes. This requires some additional code on the jeenode to check message integrity.

// Compute the MODBUS RTU CRC
uint16_t modbus_crc (volatile uint8_t buf[], int len)
{
  uint16_t crc = 0xFFFF;

  for (int pos = -1; pos < len; pos++) {
    if (pos == -1) {
      crc ^= (uint16_t)0x2D;          // Added the sync byte
    }
    else {
      crc ^= (uint16_t)buf[pos];          // XOR byte into least sig. byte of crc
    }

    for (int i = 8; i != 0; i--) {    // Loop over each bit
      if ((crc & 0x0001) != 0) {      // If the LSB is set
        crc >>= 1;                    // Shift right and XOR 0xA001
        crc ^= 0xA001;
      }
      else                            // Else LSB is not set
        crc >>= 1;                    // Just shift right
    }
  }
  // Note, this number has low and high bytes swapped, so use it accordingly (or swap bytes)
  uint8_t temp_high_value = (uint8_t)(crc >> 8);      // Save high byte value
  crc <<= 8;                                          // Store low byte value in high byte
  crc = crc | temp_high_value;

  return crc;
}
@icarus75
Copy link
Member

CRC-16 calculation in the FLM when tx'ing jeenode-type packets is correct. Should you still experience CRC-type issues, please re-open this FR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants