Modbus Communication Protocol and Register Description for Brushless Motor Drivers

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

Modbus Communication Protocol and Register Description for Brushless Motor Drivers
Modbus Communication Protocol and Register Description for Brushless Motor DriversFigure

1. Communication protocol

0x07, 0x09, 0x19, 0x01, 0x11, 0x0a, 0x1a, 0x02, 0x12, 0x0b, 0x1b, 0x03, 0x13, 0x0c, 0x1c, 0x04, 0x14, 0x0d, 0x1d, 0x05, 0x15, 0x08, 0x18, 0x00, 0x10,

0x03 0x06 0x10

0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80,  0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0 xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,

  • 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
  • > The data bit is 8 Position.
  • > Verify as“None+1 Stop position”.
  • > The address of the slave station is fixed at 1.  User defined communication parameters:
  • > Configurable range of baud rate 9600-115200bps.
  • > The data bits are fixed at 8 Position.
  • > The verification method can be configured as::  “I am+1 Stop position”, “Strange+1 Stop position”And“None+2 Stop position”.
  • > The range of sub station addresses can be set 1~255.

When the interruption of data frame communication exceeds 4 The packaging time of one byte is determined as frame reception timeout. When a frame timeout occurs, The previously received data will be Deemed invalid.

1.2 MODBUS-RTU Frame format

This drive supports MODBUS of Read and hold registers 0x03(Write a single register) and), 0x06(Write multiple register function codes 0x10(Read and hold registers.

1.2.1 0x03 Sent by the main station

Byte:

Content12345678
Start registerADR0x03High byte Start registerLow byte Register high byte countNumber of registersLow byte Low byteCRC High byteCRC  The

Byte 1 Slave station address code ADR: The (=001~254) .

Byte 2 Read register value function code 0x03: The.

Byte 3, 4 The starting address of the register to be read:  The.

Byte 5, 6 The number of registers to be read:  The.

Byte 7, 8 From bytes:  Arrived 1 of 6 of CRC16 Verification code .

Return from the station:

Byte1234 , 56 , 7…M-1, MM+1M+2
ContentADR0x03Total number of bytesRegister data Register 1data Register data Low byte 2…High MCRC ByteCRC The Byte

Slave station address code 1 The ADR: Byte (=001~254) .

Return to read function code 2 The 0x03: Byte.

From 3 Arrived: include 4 And M (The total number of bytes 4 The M) Arrived.

Byte 4 Register data M The:  Byte.

From bytes M+1, M+2 Arrived: of Verification code 1 When receiving an error from the slave station M Return from the station CRC16 Byte.

Content, Exception code:

Low byte12345
High byteADR0x83TheCRC ByteCRC The

Byte 1 The Byte 2 Slave station address code Error reading register value 3 Exception code

ADR: See table (=001~254) .

0x83: The.

Byte:  From bytes 1.1.

Arrived 4, 5 of Verification code:  Write a single register 1 to 3 of CRC16 Verification code.

1.2.2 0x06 Write a single register

Sent by the main station:

Byte12345678
ContentADR0x06Register high Byte addressRegister low Byte addressHigh byte dataLow byte dataCRC Low byte codeCRC Code height byte

When receiving correctly from the station, Return from the station:

Byte12345678
ContentADR0x06Register high Byte addressRegister low Byte addressHigh byte dataLow byte dataCRC Low byte codeCRC Code height byte

When receiving an error from the slave station, Return from the station:

Byte12345
ContentADR0x86Exception codeCRC Low byteCRC High byte

The 1 Byte The 2 Byte The 3 Byte

ADR: Slave station address code (=001~254) .

0x86: Write register value error function code.

Exception code:  See table 1.1.

The 4, 5 Byte: From bytes 1 Arrived 3 of Verification code CRC16 Write multiple register values.

1.2.3 0x10 Sent by the main station

Byte:

Content1234567
Start registerADR0x10High byte address Start registerLow byte address Number of registersHigh byte count Number of registersLow byte count Data wordTotal number of sections Total number of sections
Byte8,910,11N,N+1N+2N+3
ContentRegister data 1Register data 2Register data MCRC Low byte codeCRC Code height byte

When receiving correctly from the station, Return from the station:

Byte12345678
ContentADR0x10Register high Byte addressRegister low Byte addressNumber of registers High byte countNumber of registers Low byte countCRC Low byte codeCRC Code height byte

When receiving an error from the slave station, Return from the station:

Byte12345
ContentADR0x90Exception codeCRC Low byteCRC High byte

The 1 Byte The 2 Byte The 3 Byte

ADR:  0x90:   Exception code:

Slave station address code (=001~254) .

Error writing register value.

See table 1.1.

The 4, 5 Byte: From bytes 1 Arrived 3 of Verification code CRC16 Error exception code.

1.2.4 Exception code

MODBUS As shown in the table : The 1.1 ShowTable

Abnormal code table 1. 1 MODBUS Exception code

meaningIllegal function code
0x01Illegal data address
0x02Illegal data values
0x03Substation equipment malfunction
0x04The request has been confirmed
0x05But it takes a long time to process the request, Busy with devices
0x06Busy with devices
0x08Storage parity error
0x0AUnavailable gateway
0x0BGateway target device response failed

2. Standard register definition

2.1 Device description information register

The device description information register is shown in the table 2.1 TheShow.

Table 2. 1 Device description information register

Register addressDescriptionValue rangeSupport function coderemarks
0x0000 (0)Equipment identification number 0x03Each model has a corresponding device identification number
0x0001 (1)Device version 0x03High byte main version number, Low byte is the sub version number
0x0002 (2)Maximum current 0x03Multiply the numerical value by0.01For the current value, The unit isA
 0x0003~0x0007(3)~(7) retain  0x03  

2.2 Real time status register

The real-time status register is shown in the table 2.2 TheShow.

Table 2.2 Real time status register

Register addressDescriptionValue rangeSupport function coderemarks
0x0008 (8)Real time current0~655350x03Multiply the numerical value by 0.01 For the current value, The unit is A
0x0009 (9)The high half of real-time speed -110000~110000 0x03 Real time rotational speed, unit: RPM
0x000A (10)Low half word of real-time speed
        0x000B (11)        Error status         0~13         0x030 No errors1: Blocked rotor shutdown2: Phase sequence not studied3: Phase anomaly4: Phase line overcurrent5: Bus overcurrent6: Voltage too high7: Voltage too low, 8: Abnormal phase learning9: Overload abnormality10: 485 Communication interruption11: CAN Communication interruption12: Bus voltage is too high13: Excessive temperature, 14: Unconscious startup failed15: Abnormal phase current
0x000C (12)Internal potentiometer voltage0~33000x03The unit is mV
0x000D (13)External signal voltage0~100000x03The unit is mV
0x000E (14)retain   
0x000F (15)retain   
 0x0010 (16) Enable level 0,1 0x030: Low level1: High level
 0x0011 (17) Brake voltage level 0,1 0x030: Low level1: High level
 0x0012 (18) Directional voltage level 0,1 0x030: Low level1: High level
                        0x0013 (19)   Control mode                 0x07, 0x09, 0x19, 0x01, 0x11, 0x0a, 0x1a, 0x02, 0x12, 0x0b, 0x1b, 0x03, 0x13, 0x0c, 0x1c, 0x04, 0x14, 0x0d, 0x1d, 0x05, 0x15, 0x08, 0x18, 0x00, 0x10, 0x030-4 Definition from low to high in position: ①The 4 Position indicates no sensation 0 Or have feelings 1, ②The 3 Position represents open-loop 0 Or closed loop 1, ③The 0-2 Position representation mode: Phase sequence learning (111) , Communication control (000) , Internal potentiometer (001) , Analog quantity (010) , PWM (011) ,model airplane PWM (100) ,Joystick (101) ④Value meaning: 0x07: Phase sequence learning,  0x09: Non sensitive/closed-loop/internal potentiometer control, 0x19: Sensing/closed-loop/internal potentiometer control, 0x01: Non sensitive/open-loop/internal potentiometer control, 0x11: Sensing/open-loop/internal potentiometer control,  0x0a: Sensorless/closed-loop/analog control, 0x1a: Sensory/closed-loop/analog control, 0x02: Sensorless/open-loop/analog control, 0x12: Sensible/open-loop/analog control,  0x0b: No sensation/closed loop/PWM Control, 0x1b: Sensation/closed loop/PWM Control, 0x03: No sensitivity/open-loop/PWM Control, 0x13: Sensible/open-loop/PWM Control,  0x0c: Non sensory/closed-loop/model airplane PWM Control, 0x1c: Sensory/closed-loop/model airplane PWM Control, 0x04: Non sensory/open-loop/model airplane PWM Control, 0x14: Sensible/open-loop/model airplane PWM Control,  0x0d: Sensorless/closed-loop/joystick control, 0x1d: Sensory/closed-loop/joystick control, 0x05: Sensorless/open-loop/joystick control, 0x15: Sensation/open-loop/joystick control,  0x08: Sensorless/closed-loop/communication control, 0x18: Sensing/closed-loop/communication control, 0x00: Sensorless/open-loop/communication control, 0x10: Sensing/open-loop/communication control,
0x0014(20)Load rate0~10000x03Multiply the numerical value by 0.1%For PWM percentage, The unit is‰
0x0015(21)Input PWM Duty cycle0~10000x03Multiply the numerical value by 0.1%For input PWM Duty cycle, The unit is‰
0x0016(22)Voltage0~1000x03Power supply voltage, The unit is V
0x0017(23)Temperature-200~2000x03Circuit board temperature, The unit is℃
0x0018(24)retain   

2.3  Motor control register

Motor control registerAs shown in the table 2.3 TheShow.

Table 2.3 Motor control register

Register addressDescriptionValue rangeSupport function coderemarks
 0x0020 (32) stop it 0, 1, 2 0x03 0x060: Normal stop1: Emergency braking2: Freedom stops
0x0021 (33)Set the upper half of the target parameterClosed loop: -Maximum speed~ Maximum speed open-loop: -1000~1000  0x03 0x06 0x10When the speed control is closed-loop, Representing speed, The unit is RPM; When the speed control is open-loop, Representative PWM, Multiply the numerical value by 0.1%For PWM percentage. Positive numbers indicate positive rotation, Negative numbers indicate reversal,  0 Normal stop
0x0022 (34)Set the lower half of the target parameter
 0x0023 (35) Test control 0, 1 0x03 0x060: Cancel testing, 1: Phase sequence learning
 0x0024 (36) Output control 0, 1 0x03 0x060: Output low level1: Output high level
0x0025~0x27(37)~ (39) retain   

2.4  Motor parameter configuration register

The motor parameter configuration register is shown in the table 2.4 TheShow.

Table 2.4 Motor parameter configuration register

Register addressDescriptionValue rangeSupport function coderemarks
0x0028 (40)Rated current of motor0~15000x03 0x06 0x10Multiply the numerical value by 0.01 For the current value,  The unit is A
0x0029 (41)The higher half of the maximum speed of the motor 0~110000 0x03 0x06 0x10 The unit is RPM
0x002A (42)The lower half of the maximum speed of the motor
0x002B (43)The higher half of the minimum speed of the motor 0~110000 0x03 0x06 0x10The unit is RPM, Generally set in 200RPM following
0x002C (44)The lower half of the minimum speed of the motor
 0x002D (45)Number of motor poles 0~65535 0x03 0x06 0x10Number of north and south magnetic poles of stator, It is magnetic The extreme half
 0x002E (46) electric machinery 1 , 2 Phase sequence dataThe high byte is 0~6The low byte is 0~6 0x03 0x06 0x10The low byte is 1 The high byte is 2 Phase
 0x002F (47) electric machinery 3 , 4 Phase sequence dataThe high byte is 0~6The low byte is 0~6 0x03 0x06 0x10The low byte is 3 The high byte is 4 Phase
 0x0030 (48) electric machinery 4 , 6 Phase sequence dataThe high byte is 0~6The low byte is 0~6 0x03 0x06 0x10The low byte is 4 The high byte is 6 Phase
 0x0031 (49) Phase sequence learning status 0,1 0x03 0x06 0x100: Not studying1: Already studied
   0x0032 (50)   No sensory startup load size   0~4   0x03 0x06 0x100: Light load1: Medium load2: Overloading3: Small inertia load4: Large inertia load
0x0033 (51)Closed loop speed acceleration100~Maximum speed0x03 0x06 0x10The unit is RPM/S
0x0034 (52)Closed loop speed deceleration acceleration100~Maximum speed0x03 0x06 0x10The unit is RPM/S
0x0035 (53)Open loop speed acceleration4~5000x03 0x06 0x10The unit is%/S
0x0036 (54)Open-loop speed deceleration acceleration4~5000x03 0x06 0x10The unit is%/S
 0x0037 (55) Stop mode 0, 1, 2 0x03 0x06 0x100: Normal stop1: Emergency braking2: Freedom stops
 0x0038 (56) Automatic reversing mode 0, 1, 2 0x03 0x06 0x100: Normal commutation1: Emergency stop reversing
 0x0039 (57) Shutdown lock-in current 0~1500 0x03 0x06 0x100: Do not stop the machine and lock other values: Multiply the numerical value by 0.01 For the current value, The unit is A
0x003A~0x 3F(58)~ (63) retain   

2.5 System parameter configuration register

System parameter configuration registerAs shown in the table 2.5 TheShow.

Table 2.5 System parameter configuration register

Register addressDescriptionValue rangeSupport function coderemarks
0x0040 (64)Blockage shutdown time0~666350x03 0x06 0x10The unit is mS
0x0041 (65)Protect the shutdown current0~42000x03 0x06 0x10Multiply the numerical value by 0.01 For the current value,  The unit is A
0x0042 (66)Maximum value of internal potentiometer control threshold0~33000x03 0x06 0x10The unit is mV
0x0043 (67)Minimum threshold value for internal potentiometer control0~33000x03 0x06 0x10The unit is mV
0x0044 (68)Maximum value of external input control threshold0~100000x03 0x06 0x10The unit is mV
0x0045(69)Minimum value of external input control threshold0~100000x03 0x06 0x10The unit is mV
0x0046 (70)Maximum value of protection voltage threshold (Overvoltage protection Voltage) 8~560x03 0x06 0x10 Protection voltage range, The unit is V
0x0047 (71)Minimum value of protection voltage threshold (Undervoltage protection Voltage) 8~560x03 0x06 0x10
 0x0048 (72)Voltage protection settings 0,1 0x03 0x06 0x100: Not protecting1: Voltage protection
   0x0049(73)   output type   0,1,2,3,4,5   0x03 0x06 0x100: Not outputting (I.e. outputting low power Flat) 1: Long output2: Alarm signal output3: FG Feedback signal output4: Shutdown signal output5: Communication control

2.6 PID Parameter configuration register

Closed-loop control PIDThe parameter configuration register is shown in the table 2.6 TheShow.

Table 2.6 Closed-loop control PID Parameter configuration register

Register addressDescriptionValue rangeSupport function coderemarks
0x004A (74)Speed closed-loop P High coefficient half letter Suggestions 1~327680 0x03 0x10 Divide the value by 32768 For actual values
0x004B (75)Speed closed-loop P Low coefficient half letter
0x004C (76)Speed closed-loop I High coefficient half letter Suggestions 1~326780 0x03 0x10 Divide the value by 32768 For actual values
0x004D (77)Speed closed-loop I Low coefficient half letter
0x004E (78)Speed closed-loop D High coefficient half letter Suggestions 1~326780 0x03 0x10 Divide the value by 32768 For actual values
0x004F (79)Speed closed-loop D Low coefficient half letter

2.7 Communication parameter configuration register

CommunicationThe parameter configuration register is shown in the table 2.6 TheShow.

Table 2.7 Communication parameter configuration register

Register addressDescriptionValue rangeSupport function coderemarks
0x0050 (80)485Communication interruption braking time0~666350x03 0x060x10The unit is S
0x0051 (81)485Address of communication equipment0~2550x03 0x060x10Modbus From device address
    0x0052 (82)    485Communication serial port baud rate    0~4   0x03 0x060x100: 96001: 192002: 384003: 576004:  115200unit bps
  0x0053 (83)  485 Communication serial port verification method  0~3  0x03 0x060x100: No+stop position1: I am+1 Stop position2: Strange+1 Stop position3: None+2 Stop position
0x0054(84)~0 x0059 (89)retain   

3.CRC16 The calculation

C Language CRC Generate functions such asProgram 3.1As shown. All possibilities CRC  The values are pre installed in two arrays, When calculating the content of the message  Simple indexing is sufficient.  An array contains 16 Position CRC All domains 256 Possible high-order bytes, Another array contains the values of the lower byte.  This type of index access CRC  The method provides a new calculation for each new character in the comparison message buffer CRC  Faster methods.

Note This function performs high/low internally: Byte exchange CRC  This function returns what has already been swapped. Value CRC  in other words. From this, The function returns The value can be directly placed in the message for sending CRC The function takes two parameters.

Pointing to the content used for generation:

unsigned char *puchMsg; Pointer to the binary data message buffer CRC  The number of bytes in the message buffer.

unsigned short usDataLen; Note:.

following: The generated function program is excerpted from CRC16 Program <MODBUS over Serial Line Specification and Implementation Guide

V1.02> .

Generate a list of function programs 3.1   CRC16 High byte

/*  Value CRC Low order bytes*/

static unsigned char auchCRCHi[] = {

0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81,

0x40

} ;

/* Value CRC Function to*/

static char auchCRCLo[] = {

0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4,

0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD,

0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,

0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7,

0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,

0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2,

0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,   0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB,  0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,

0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91,

0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,

0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88,  0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,

0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80,

0x40

};

unsigned short CRC16(puchmsg, usDataLen)     /*  Type return unsigned short  Used for calculation CRC */

unsigned char *puchMsg,                                      /*  The message CRC  The number of bytes in the message*/

unsigned short usDataLen/*  High byte initialization*/
{ 
unsigned charuchCRCHi = 0xFF;/* CRC  Low byte initialization*/

unsigned charuchCRCLo = 0xFF;     /* CRC  Query table index*/

unsigned uIndex ;           /* CRC  Complete the entire message buffer*/

while (usDataLen--)

{

/*  Calculation*/

uIndex = uchCRCLo ^ *puchMsg++; /*  Calculation CRC */

uchCRCLo = uchCRCHi ^ auchCRCHi[uIndex];

uchCRCHi = auchCRCLo[uIndex];

}

return (uchCRCHi << 8 | uchCRCLo);

}

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.