cancel
Showing results for 
Search instead for 
Did you mean: 

Sample code for MCP

shraddhs10
Associate II

Hi,

Is there a sample code to control the STM32 motor board with UART from a host PC

I'm mostly looking for setting and getting the encoder angles and speed control with the UART

 

4 REPLIES 4
Gael A
ST Employee

Hello shraddhs10,

While generating your code using the MCSDK WorkBench, the MCP over UART will automatically be included in your project. You can check whether it is the case in the User Interface tab of the WorkBench UI. This will allow you to connect the MotorPilot tool to your board and access several informations, such as speed and encoder angle. You can find further information on the Motor Control Wiki and on MCSDK documentation. The latter can be found by clicking About -> Documentations -> Documentation on your MCDSK WorkBench

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.

Hope this will help,
Gaël A.
shraddhs10
Associate II

I am able to control the motor with the MotoPilot tool. But as my end goal is to implement a stand alone application to control the motor board instead of using the tool.

I went through the documentation but the info on setting/getting the register for encoder angle and the speed are ot very clear 

Is there a way to control the motor control board from a another processor/ host PC? 

I am trying to connect with UART and sending the commands to the motor control board but it is not working

Code as below:

>>> import serial
>>> x = serial.Serial('COM8', 1843200)

>>> x.write(b"\x30") // START_STOP_MOTOR command
1
>>> x.write(b"\x18") // START_MOTOR command
1
>>> x.write(serial.to_bytes([0x18])) // START_MOTOR command
1
>>> x.write(serial.to_bytes([0x30])) // START_STOP MOTOR command
1

I am getting CMD_NOK always.

But this functionality is working through the MotorPilot GUI

I'm working on this at the moment. You need to follow the packet structure that is described in the documentation that they hide on your computer when you install mcsdk (I can't find it online anywhere) Look in C:\Program Files (x86)\STMicroelectronics\MC_SDK_6.2.0\Documentation or whatever is most similar to how you set up your environment. 

 

I've been at it for about a day, its not too bad. A bit of a dense read and I wish they just had some available source code considering they wrote the motor pilot code is theirs.