
TimerInitStructure.TIM_RepetitionCounter = 0 TimerInitStructure.TIM_ClockDivision = 0 TimerInitStructure.TIM_CounterMode = TIM_CounterMode_Up TIM_TimeBaseInitTypeDef timerInitStructure Now configuring timer: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE) Check your concrete MCU datasheet.įirstly output pin should be configured as AF, with push-pull and resistor is UP. GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_2) įor example I connect STEP output from MCU PA9 to A4988 STEP input. RCC_APB2PeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE) Here is an example of STEP PIN control: RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE)
#STM32 DRIVER STEPER MOTOR FULL#
SLEEP INPUT PIN A4988 must get HIGH from your MCU, also it is very useful to control it when your stepper job done, else if you leave it always HIGH, stepper motor will eat current and will heat up at idle state.Īlso there are 3 MICROSTEPPING PINS, those are for controlling stepping.Īs you just starting to play, it will be enough connect those pins to GND, you'll get full stepping regime.If you'll control those pins you can get other regimes like 1/2 stepping, 1/4,1/8,1/16.Īnd general pin is STEP pin, it should be driven with TIMER as PWM output with constant pulse width and alternating period. RESET INPUT PIN A4988 must get HIGH from your MCU.ĮNABLE INPUT PIN A4988 must get LOW from your MCU. Anyway you should read A4988 data sheet very accurately.ĭIR PIN is simply for direction, push-pull pin configuration and HIGH/LOW values controls direction, clock wise, anti clock wise. For example you have small stepper motor, and setting too high VREG value, than A4988 will sink too much current and your motor will glitch. Actually it controls current for your motor. It should get from 0 to 2000mV if I remember.

You should check it.Īlso from power pins very decisive VREG pin. SENSE1, SENSE2 pins can be connected to 0.25omh resistors. ROSC pin is for low power mode, so here you should calculate, if you just ignore it, be sure to connect at least to 10k resistor. So recheck pins.Įspecially ROSC pin, SENSE1, SENSE2 pins as those may cause that motor wont work even if other pins are ok. If you have some kind of custom board, there may be some flaws. Anyway you should have some kind of hardware, because A4988 needs extra components for current control (resistors), and some capacitors.

Actually I have wrote whole driver for a4988, it is irq based.
