MKS SERVO42C Closed loop Stepper Motor Manual(3) Serial communication - makerbase-mks/MKS-SERVO42C GitHub Wiki

Part 1 Hareware

1.1 List

Number Name Quantity
1 MKS SERVO42C V1.0(with motor) 1
2 6pin data cable 1
3 CH340 MODULE 1
4 DC 12V-24V power supply 1

The hardware list is shown in the figure below.

1.2 Connection

Number MKS SERVO42C V1.0 CH340 MODULE
1 TX RX
2 RX TX
3 GND GND
4 3V3 /

The serial communication wiring diagram is as shown in the figure below:

Part 2 Software preparation

  1. The serial communication assistant used can be downloaded through Github, as shown in the figure below.

  1. The serial port assistant is shown in the figure below.

Part 3 Serial communication format

  1. The sending and receiving settings of the serial port assistant are hex, and command bytes are not prefixed with 0x.

  2. The serial communication baud rate of the driver board 38400 is set on the UartBaud option

  1. The serial ID(ex) of the driver board is set on the UartAddr option. Default : e0
  1. For each command, do not send less or omit a parameter.

  2. The returned data format is the high 8 bits first.

  3. Returning ID 01 means that the command is correct, and returning ID 00 means that the command is wrong.

Part 4 Serial communication description

Note: Please set the serial port ID first.(default:e0) The default ID for the following chapters is e0.

4.1 Read parameter coommand

  1. command 1 : e0 30

    read the encoder value (the motor should be calibrated)

    Return e0 and the value(uint16_t) of encoder. The returned value ranges from 0 to FFFF.

    Example:

    Send e0 30

    return e0 40 00

  2. command 2 : e0 33

    Read the number of pulses received

    Return e0 and the number of pulses(int32_t).

    Example:

    Send e0 33

    return e0 00 00 01 00 (256 pulses)

  3. command 3 : e0 36

    read the angle of the motor shaft.

    Return e0 and the angle(int32_t).

    The motor rotates one circle, the corresponding angle value range is 0~65535.

    Example:

    Send e0 36

    return e0 00 00 40 00 (angle 90 °)

  4. command4: e0 39

    read the error of the motor shaft angle.

    Return e0 and the error(int16_t).

    The error is the difference between the angle you want to control minus the real-time angle of the motor, 0-FFFF corresponds to 0~360°, for example, when the angle error is 1°, the return error is 65536/360= 182.444, and so on.

    Example:

    Send e0 39

    return e0 00 B7 (error 1 °)

  5. command5: e0 3a

    read the En pins status.

    Return e0 and the status (uint8_t).

    Status: 01-enable;02-disable;00-error

    Example:

    Send e0 3a

    return e0 01 (enable)

  6. command6: e0 3e

    read the motor shaft status.

    Return e0 and the status (uint8_t).

    Status: 01-blocked; 02- unblocked; 00-error

    Example:

    Send e0 3e

    return e0 02 (unblocked)

4.2 Set subdivision command

  1. command7: e0 84 xx

    Set subdivision from 1 to 256, the value will show in the screen of MStep option.For example:

    Send “e0 84 07”,set 7 subdivision

    Send “e0 84 4e”,set 78 subdivision

    Send “e0 84 00”,set 256 subdivision

    And so on...

    Return e0 and the result (uint8_t).

    result: 01- successful; 00- Failure

    Example:

    Send e0 84 1a (26 subdivision)

    return e0 01 (successful)

4.3 Serial control command

  1. command8: e0 f3 xx

    Set the En pin status in CR_UART mode.

    status: 01-enable; 00-disable

    Return e0 and the result (uint8_t).

    result: 01- successful; 00- Failure

    Example:

    Send e0 f3 01 (enable)

    return e0 01 (successful)

  2. command9: e0 f6 xx

    run the motor forward / reverse in a Constant speed.

    The XX highest bit indicates direction, and the XX lowest 7 bits indicate 128 speed gears, for example:

Such as:

Send “e0 f6 01”,The motor rotates forward at the speed of 1;

Send “e0 f6 81”,The motor reverses at the speed of 1;

Send “e0 f6 5a”,The motor rotates forward at the speed of 90;

Send “e0 f6 da”,The motor reverses at the speed of 90;

Return e0 and the result (uint8_t).

result: 01- successful; 00- Failure

Example:

Send e0 f6 10 (speed of 16)

return e0 01 (successful)

  1. command10: e0 f7

    stop the motor.

    Return e0 and the result (uint8_t).

    result: 01- successful; 00- Failure

    Example:

    Send e0 f7

    return e0 01 (successful)

  2. command11: e0 ff xx

    Save/Clear the status set in command9.

    xx: c8-save; ca-clean

    Return e0 and the result (uint8_t).

    result: 01- successful; 00- Failure

    Example: Send e0 ff c8 (save the status)

    return e0 01 (successful)

    Attention:The motor can rotates clockwise or counterclockwise at a constant speed when powered on.

    For example:

    Send e0 f6 10

    return e0 01

    Send e0 ff c8

    return e0 01

    the motor will always rotates clockwise in speed(16) when power on.

  3. command12: e0 fd XX XX XX

    The motor run to an angle in a speed.

    The third byte(XX) defines the direction and speed, such as command9.

    The last two bytes(XX XX) define the number of pulses.if(XX XX = 0C 80),the motor(1.8 °, subdivision 16) will rotates one circle.

Return e0 and the result (uint8_t).

result: 01- successful; 00- Failure

For example: (the motor(1.8 °, subdivision 16))

send “e0 fd 01 0c 80”, the motor rotates forward 360 °in speed 1.

send “e0 fd 86 0c 80”, the motor rotates reverses 360 °in speed

Example:

Send e0 fd 32 0c 80

return e0 01 (successful)

Part 5 Run the motor with serial command

5.1 Configure the motor

  1. Select “CR_UART”mode in the menu,as shown below.

  1. Configure the baudrate, as shown below.

  1. Configure the serial port ID, as shown below.
  1. Configure the Uart Assistant

    Select the Channel; (such as COM5)

    Select the Baudrate; (such as 38400, Must be equal to motor baudrate)

    Recv Options: select “HEX”

    Send Options: select “HEX”

    As shown below:

5.2 Read the angle of the motor shaft

Send e0 36

return E0 00 00 00 4C

As shown below:

5.3 Run the motor forward/reverse

Send e0 f6 00

return E0 01

The motor rotates forward in speed 0.

As shown below:

Send e0 f6 80

return E0 01

The motor rotates reverse in speed 0.

As shown below:

Thanks for reading!

https://github.com/makerbase-mks/MKS-SERVO42C