My stepper motor turn just in one direction

Hi, I have a problem with my stepper motor 17HS4401, I connected it with DVR8825( driver) and arduino uno

I set vref to 1.2v and I upload this code

/* stepper motor control code for DRV8825
 * 
 */

 // define pin used
 const int stepPin = 9;
 const int dirPin = 8;
 
 void setup() {
 // set the two pins as outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

}

void loop() {
digitalWrite(dirPin,HIGH); //Enables the motor to move in a perticular direction
// for one full rotation required 200 pulses
for(int x = 0; x < 200; x++){
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(500);
}
delay(1000); // delay for one second


digitalWrite(dirPin,HIGH); //Enables the motor to move in a opposite direction
// for three full rotation required 600 pulses
for(int x = 0; x < 600; x++){
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(500);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(500);
}
delay(1000); // delay for one second
}

The motor should turn in the two directions, but it turns just in one direction !!!

Hello,

As your code is written now it is only going to go in one direction. If you want your stepper motor to go in both directions, you should change one of your digitalWrite(dirPin,HIGH); statements to digitalWrite(dirPin,LOW);.

By the way, your VREF voltage is set too high for the DRV8825, The VREF voltage should be no higher than 0.75V if you are using our DRV8825 carrier without additional cooling (e.g. forced airflow or heatsinks). You can see more about setting the current limit for the DRV8825 in the “Current limiting” section of its product page.

-Derrill