Encoder motor moving unidirection (only in one direction)
I am working with an STM32H723ZG Nucleo-144 board and a small GA12-type encoder DC gear motor connected through a motor driver.
My connections are:
- Motor driver PWM → D15 / PD15, configured as TIM4 Channel 4 PWM
- Motor driver DIR → Arduino A2 / PC3, configured as GPIO Output
- Encoder C1 → D6 / PE9, configured as TIM1 Channel 1
- Encoder C2 → D5 / PE11, configured as TIM1 Channel 2
- Encoder is configured in TIM1 Encoder Mode TI12
PWM is working and the motor rotates, but I cannot make the motor rotate in the opposite direction. I have tried setting the DIR pin both HIGH and LOW:
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_SET);
HAL_Delay(3000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_Delay(3000);
However, the motor continues rotating in the same direction.
I have confirmed in STM32CubeMX that A2 corresponds to PC3 and PC3 is configured as GPIO output. I am using TIM4 CH4 for PWM and TIM1 CH1/CH2 for the encoder.
What could be causing the DIR signal not to reverse the motor direction? Is there anything specific I should check in the STM32 GPIO configuration or in the motor-driver connection?
