Code/CRC16

From HITEC_HELP
Revision as of 01:38, 10 February 2023 by Choiyh (talk | contribs) (Created page with " == CRC16 == <pre> uint16_t x_crcAddByte(uint16_t crc_val, uint8_t byte) { crc_val ^= (uint16_t) ((uint16_t) (byte) << 8U); for (uint8_t j = 0; j < 8; j++) {...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

CRC16

uint16_t x_crcAddByte(uint16_t crc_val, uint8_t byte)
{
    crc_val ^= (uint16_t) ((uint16_t) (byte) << 8U);
    for (uint8_t j = 0; j < 8; j++)
    {
        if (crc_val & 0x8000U)
        {
            crc_val = (uint16_t) ((uint16_t) (crc_val << 1U) ^ 0x1021U);
        }
        else
        {
            crc_val = (uint16_t) (crc_val << 1U);
        }
    }
    return crc_val;
}