Can't move motors on CNC v3 shield with custom code

Hi, I am writting my own CNC stepper-motor firmware and everything freezed on point that I am unable to move the steppers. I created simple program for flashing led which worked (pin 2-gnd: half brigthness, and 8-gnd: full brightness), so I plugged in cnc shield, but nothing happened. On init, I set ‘enable’ pin to HIGH (pin 8 / portb0), set ‘direction X’ to HIGH (pin 5 / portd5) and start toggling ‘step X’ (pin 2 / portd2) every tick. I basically wrote 2 programs, both are working fine with led, but don’t work with stepper motor shield.

This one is non-arduino:

#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdint.h>

int main() {
	// Timer enable
	

	// Enable internal transistors for higher current
	//DDRD = (1<<2) | (1<<5);
	//DDRB = (1<<0);
	PORTB = (1 << 0); //pin 8 high
	PORTD = (1<<5); // X dir 1
	PORTD = PORTD & ~(1 << 2); //X step 0

	//uint8_t saved_state = SREG;
	//cli();

    OCR2A = 127;
    TCCR2B = (1 << CS21); //prescaller 8
    TCCR2A = (1 << WGM21); //CTC, top=ocra
    TIMSK2 = (1 << OCIE2A); // global interrupts enabled

    //SREG = saved_state; //reneable interrupts
    sei();
	
	//Infinite loop, just stepping
	while(1) {}
	__builtin_unreachable();
}

//Called every 64 us
char bef = 0;
ISR(TIMER2_COMPA_vect) {
	PORTD = PORTD & ~(1 << 2) | ((bef = !bef) << 2);
}

and this one is written in arduino:

// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing

byte directionPin = 5;
byte stepPin = 2;
int pulseWidthMicros = 20;  // microseconds
int mcrSteps = 250; // delay between steps


void setup() { 

  Serial.begin(115200);
  Serial.println("Starting StepperTest");

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(8, OUTPUT); //enable pin

  delay(3000);

  digitalWrite(8, HIGH); // enable
  digitalWrite(directionPin, HIGH);

  
  int n = 0;
  while(1) {
    Serial.print((n++&1)?"_":"-");
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros); // probably not needed
    digitalWrite(stepPin, LOW);
    
    delayMicroseconds(mcrSteps);
  }
}

void loop() { 
}

Of course, I tested the shield with latest GRBL and it worked OK, stepper was moving. Probably I need to turn any PIN on, but I really don’t know which one. Thanks

Lol, enable must be LOW.

Maybe it's necessary to physically connect load resistors to your driver output...... to manually check and measure each driver output. Just to make sure your programmed control signals are generating the required driver output. Eg... just set one command that drives the driver output to one state. Then use a multimeter to see if the output is doing the right thing.

I got it working. I just found out the enable pin must be set to LOW in order to activate the shield, which is pretty weird. Anyway the motor is spinning and everything looks like its working.

Good to know you sorted it.