cancel
Showing results for 
Search instead for 
Did you mean: 

How to change stepper motor direction using modbus

Lchal.1
Associate II

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

4 REPLIES 4
Jack Peacock_2
Senior III

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

Ozone
Lead II

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).

 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

Thank you