自己看源码吧 CRC校验高低位需要调整的话,自己动手
/** @defgroup RTU_Private_Functions RTU Private Functions
* @{
*/
/**
*
@Brief RTU CRC16 计算
*
@param buffer 数据指针
* @param buffer_length 数据长度
*
@Return CRC16 值
*/
static uint16_t agile_modbus_rtu_crc16(uint8_t *buffer, uint16_t buffer_length)
{
uint8_t crc_hi = 0xFF; /* high CRC byte initialized */
uint8_t crc_lo = 0xFF; /* low CRC byte initialized */
unsigned int i; /* will index into CRC lookup */
/* pass through message buffer */
while (buffer_length--) {
i = crc_hi ^ *buffer++; /* calculate the CRC */
crc_hi = crc_lo ^ _table_crc_hi
;
crc_lo = _table_crc_lo;
}
return (crc_hi << 8 | crc_lo);
}
自己看源码吧 CRC校验高低位需要调整的话,自己动手
/** @defgroup RTU_Private_Functions RTU Private Functions
* @{
*/
/**
*
@Brief RTU CRC16 计算
*
@param buffer 数据指针
* @param buffer_length 数据长度
*
@Return CRC16 值
*/
static uint16_t agile_modbus_rtu_crc16(uint8_t *buffer, uint16_t buffer_length)
{
uint8_t crc_hi = 0xFF; /* high CRC byte initialized */
uint8_t crc_lo = 0xFF; /* low CRC byte initialized */
unsigned int i; /* will index into CRC lookup */
/* pass through message buffer */
while (buffer_length--) {
i = crc_hi ^ *buffer++; /* calculate the CRC */
crc_hi = crc_lo ^ _table_crc_hi
;
crc_lo = _table_crc_lo;
}
return (crc_hi << 8 | crc_lo);
}
举报