cancel
Showing results for 
Search instead for 
Did you mean: 

Stepper Motor doesn't stop when it is called in HAL_UART_RxCpltCallback()

NPham.3
Associate

I am using Nucleo-F401RE to control a LED and an X-Nucleo-IHM01A1 that drives a stepper motor.

The MCU receives message rxdata[3] through UART DMA Interrupt. The controlling of the LED is working correctly. However, the motor is spinning continuously without stopping when MCU receives a message to control the motor.

How can I make the stepper motor work correctly with DMA interrupt?

/* USER CODE BEGIN 1 */

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(huart);

 /* NOTE: This function should not be modified, when the callback is needed,

  the HAL_UART_RxCpltCallback could be implemented in the user file

  */

 ///Copy message

 MessageReceived();

}

void MessageReceived(){

 if (rxdata[0] == 0x0A) //Led

 {

 HAL_UART_Transmit(&huart2, rxdata, 3, 500);

 if(rxdata[1] == 1){

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); //Turn on

 } else if(rxdata[1] == 2){

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET); // Turn off

 }

 } else if (rxdata[0] == 0x0B) // Motor Control

 {

HAL_UART_Transmit(&huart2, rxdata, 3, 500);

 uint32_t n_steps = rxdata[2];

 if(rxdata[1] == 0x01){ //If receive move forward command

BSP_MotorControl_Move(0, FORWARD, n_steps);

BSP_MotorControl_WaitWhileActive(0);

 } else if(rxdata[1] == 0x02){ //If receive move backward command

BSP_MotorControl_Move(0, BACKWARD, n_steps);

BSP_MotorControl_WaitWhileActive(0);

 }

 }

}

1 REPLY 1
Laurent Ca...
Lead II

Dear @NPham.3​ 

Could you give us your complete SW and HW setup?

Best regards

==

Laurent Ca...