Skip to main content
Lchal.1
Associate III
January 21, 2021
Question

How to change stepper motor direction using modbus

  • January 21, 2021
  • 4 replies
  • 901 views

Hi, i am controlling my stepper motor by giving commands through modbus in stm32f103. I am able to drive motor in one direction . But i am not able to drive my motor in another direction by sending command through modbus.

can anyone please help me with it.

i have another confusion whether i need to give negative values from my modbus to drive motor in another direction or not please anyone help me with it.

Thank you

This topic has been closed for replies.

4 replies

Jack Peacock_2
Associate II
January 21, 2021

You have two options. The first is to encode direction in the 16-bit register used to specify the speed or number of steps. A positive register setting (0x0000-off, 1-0x7fff move positive direction) specifies clockwise stepping. A negative (0xffff-0x8000, 1 to 0x7fff in negative direction) specifies counterclockwise.

If you need the full 16-bit value for step count then use a one-bit register to select clockwise/counterclockwise direction. The disadvantage here is it now takes two commands to start the motor.

Jack Peacock

Lchal.1
Lchal.1Author
Associate III
January 21, 2021

 if(motion_type_absolute > 0 && motion_type_absolute < 65535 ) // positive direction

{

set direction pin as set;

}

 else if(motion_type_absolute >32767 && motion_type_absolute < 65536) //negative direction

{

set direction pin as reset;

}

is this correct logic can i add to my code to drive stepper motor in both direction.

Thank you

Ozone
Principal
January 21, 2021

To add to Jack's correct answer - the modbus protocol does not "know" of positive/negative values.

It only specifies single bits and register (16-bit) values.

The signedness is in the interpretation of the sender/receiver (master and slave in modbus terms).

Lchal.1
Lchal.1Author
Associate III
January 21, 2021

Thank you