cancel
Showing results for 
Search instead for 
Did you mean: 

Have problem on using USART2 to control motor without MotorPilot and ASPEP protocol

Changchu
Associate

Hi,

I am using MCSDK6.1.2, STM32CubeMX6.8.1, and STM32CubeIDE1.12.1 to make a control for 24v 8-pp motor with hall sensor. Motor pilot 6.1.2, Motor profiler, and 24v motor works well on NUCLEO-STM32F302R8 and X-NUCLEO-IHM07M1.

 

I prefer to use the function void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) to handle the command data(maybe use if else function to identify the command data to enable MC_StartMotor1(void) or change the hFinalSpeed value in void MC_ProgramSpeedRampMotor1( int16_t hFinalSpeed, uint16_t hDurationms )) to control motor rather than Motor pilot 6.1.2.

 

Because I still can’t understand how to use the MCP command ID to use the command in mc_api.c even though I have read ASPEP document. So I make some modification on void USART2_IRQHandler(void) in the stm32f30x_mc_it.c. I have modified USART2_IRQHandler(void) (by commenting all code generated by STM32CubeMX and adding HAL_UART_IRQHandler(&huart2); and printf("Hi!\r\n");  for testing whether HAL_UART_Receive_DMA( ) works. add extern UART_HandleTypeDef huart2; and  extern DMA_HandleTypeDef hdma_usart2_rx; )  as pictures below. However, I stil get trouble on using USART2 for receiving the command data sent through the serial com port.

USART2_IRQHandler_modify_1.jpgUSART2_IRQHandler_modify.jpg

 

Otherwise add some codes in main.c.and include "stdio.h", "stdlib.h" in main.h..as pictures below.

main_c_modify_1.jpgmain_c_modify_2.jpgmain_c_modify_3.jpgmain_c_modify_4.jpgmain_h_modify.jpg

It should print "hi everyone\r\n" at first after the stm32 board reboots, and then receive the string I send(for example T123456). However, it doesn’t print "hi everyone\r\n" at first and also gets stuck in USART2_IRQHandler(void) to print "Hi!\r\n" continuously.

 

I have already made a new code project (no use motor control only testing USART2) to test my code available or not. It works fine. So I have doubts that there is a conflict between my modified USART2 code and motor control library. Or I make a mistake on USART2 modification with motor control library? Please give me some advice about USART2 modification or example code about how to use ASPEP protocol to control motor without using Motor Pilot 6.1.2.

Can I disable entire ASPEP protocol function not to occupy the USART2, but still can use the function in mc_api.c likeMC_ProgramSpeedRampMotor1().But I can’t find anywhere to disable ASPEP Protocol in the STM32CubeMX6.8.1.

f302r8_aspep_setting.jpg

 

(Edited) I have also tried to disable the motor control protocol in MC workbench 6.1.2  at first. And add USART2 for what I need in STM32CubeMX6.8.1 later. The ASPEP files disappear in the generated code from CubeMX. Although I can receive or transmit data by USART2, my motor will get stop when I send the data(for example "T123456", and it can store the string into the buffer). In this situation, I must press reset button  again to reboot the control board then I  can use the start/stop button to start the motor to run normally. Please give me some advice about this strange problem.

 

mcp_try_remove.jpg

 

 

Here is my test code download link.

https://drive.google.com/drive/folders/1MtQTA6_e5MMLBGAggE3-CG3CYwJB9Fe4?usp=sharing

File name “uart_F302R8_test” is for only testing USART2.It can receive or transmit data.

File name “24Vmotor” is the modified code for motor control which I have lots of questions on it. 

File  name “motor_mcp_remove” is the modified code for motor control which I disable the motor control protocol in MC workbench 6.1.2  at first, but still have problem.

The baudrate of serial com port is set as 115200.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Zied b.
ST Employee

Hello @Changchu ,
It is strongly recommended to use the solution integrated into the MCSDK for uart communication with the board, so you can add your own commands, delete or modify them easily. In addition to the MCPV2 documentation you can find here:MCSDK documentation - STMicroelectronics Community

Attached is an explanatory document for adding new commands. I also remain available to help you make any necessary changes. Starting from scratch to create a communication protocol is very complex and may take a lot of time.
Regards

If you agree with my answer, please accept it by clicking on "Accept as solution".

View solution in original post

1 REPLY 1
Zied b.
ST Employee

Hello @Changchu ,
It is strongly recommended to use the solution integrated into the MCSDK for uart communication with the board, so you can add your own commands, delete or modify them easily. In addition to the MCPV2 documentation you can find here:MCSDK documentation - STMicroelectronics Community

Attached is an explanatory document for adding new commands. I also remain available to help you make any necessary changes. Starting from scratch to create a communication protocol is very complex and may take a lot of time.
Regards

If you agree with my answer, please accept it by clicking on "Accept as solution".