Management of two stepper motors

Based on STM32F030F4P6

Pinout

Pin Type Role
PA0 AIN Steppers current
PA1 AIN Input voltage 12V
PA2 AIN EndSwitch1 of motor0
PA3 AIN EndSwitch0 of motor0
PA4 PUPD Tim14Ch1 - motor0 steps
PA5 PUPD Motor1 enable
PA6 PUPD Tim3Ch1 - motor1 steps
PA7 PUPD Motor1 direction
PA9 OD USART1 Tx
PA10 FIN USART1 Rx
PA13 FINPU EndSwitch0 of motor1
PA14 FINPU EndSwitch1 of motor1
PB1 PUPD Turn off current sensor
PF0 PUPD Motor0 enable
PF1 PUPD Motor0 direction

Protocol

Any command have format “# CMD”, where # is device ID (the_conf.devID) or “-1” if there’s only one device at the bus. After it can be any number of spaces and command symbols. If the command recognized and it’s right, ALL OK would be returnded. If the command is bad, answer BADCMD. Error in command sintax: ERR. If the answer would take more than one line it would be ends by DATAEND.

First symbol of commands

All wrong commands will return BADCMD, commands with bad format or wrong number return ERR. Commands with lot of output ends with DATAEND. Some commands (like flash write) will return just ALL OK if succeed.

Getters

Getters returning more than one field ends with DATAEND meaning that’s all data.

Motors' manipulation

Next char should be ‘0’ or ‘1’ — motor’s number. If wrong, Num>1 answer would be returned. There’s only two commands in this section:

Setters

Change of any setter takes place in MCU RAM immediately. To store them permanently run write flash command.

Motor speed setters

To set motor speed to N steps per second, give command C or S with argument equal to 3000/N. E.g. to set current speed for DevID=0, motor0 to 50 steps per second give command 0SC050.

Denominator and numerator setters

Have naxt letter similar to ADC getter (D - Vdd, I - motors' I, or M - motors' U). The value of numerator shouldn’t be very large as uint32_t used in multiplications.

Device ID setter

After this command device will immediately change it’s ID, if you “lost” device after this procedure you should reboot it or (if there’s only one device on the bus) call it by “universal ID” (-1).

USART speed setter

The USART speed will be changed after next reset (e.g. by MCU software reboot command), so it don’t work without storing in the flash. Check it twice before writing as wrong numbers can make device lost until next re-flashing.