2023-07-12 10:22 PM - edited 2023-07-13 02:41 AM
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.
Otherwise add some codes in main.c.and include "stdio.h", "stdlib.h" in main.h..as pictures below.
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.
(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.
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
Solved! Go to Solution.
2023-09-07 01:43 AM
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
2023-09-07 01:43 AM
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