Hello World,
I want to control a stepper via serial communication. I found an example program on tmcl homepage but it isn't enough to me to understand how to control it.
The program is here:
//Example for sending TMCL commands as datagrams to a module.
//The functions for handling the serial port must be added by the user.
//Data types used here: UCHAR: 1 byte (unsigned char)
// INT: 4 byte integer ("long" on most MCUs)
//Opcodes of all TMCL commands that can be used in direct mode
#define TMCL_ROR 1
#define TMCL_ROL 2
#define TMCL_MST 3
#define TMCL_MVP 4
#define TMCL_SAP 5
#define TMCL_GAP 6
#define TMCL_STAP 7
#define TMCL_RSAP 8
#define TMCL_SGP 9
#define TMCL_GGP 10
#define TMCL_STGP 11
#define TMCL_RSGP 12
#define TMCL_RFS 13
#define TMCL_SIO 14
#define TMCL_GIO 15
#define TMCL_SCO 30
#define TMCL_GCO 31
#define TMCL_CCO 32
//Opcodes of TMCL control functions (to be used to run or abort a TMCL program in the module)
#define TMCL_APPL_STOP 128
#define TMCL_APPL_RUN 129
#define TMCL_APPL_RESET 131
//Options for MVP commandds
#define MVP_ABS 0
#define MVP_REL 1
#define MVP_COORD 2
//Options for RFS command
#define RFS_START 0
#define RFS_STOP 1
#define RFS_STATUS 2
#define FALSE 0
#define TRUE 1
#define UCHAR unsigned char
int x=0;
void setup() { //my edit
Serial3.begin(9600); //my edit
}
void loop() { //my edit
SendCmd(1, 2, 0, 1200, 183); //my edit, Checksum, HEX(B8)=DEC(183)
}
void SendCmd(int Address, int Command, int Type, int Motor, long int Value)
{
UCHAR TxBuffer[9];
UCHAR i;
TxBuffer[0]=Address;
TxBuffer[1]=Command;
TxBuffer[2]=Type;
TxBuffer[3]=Motor;
TxBuffer[4]=Value >> 24;
TxBuffer[5]=Value >> 16;
TxBuffer[6]=Value >> 8;
TxBuffer[7]=Value & 0xff;
TxBuffer[8]=0;
for(i=0; i<8; i++)
TxBuffer[8]+=TxBuffer*;*
- //Now, send the 9 bytes stored in TxBuffer to the module*
- //(this is MCU specific)*
}
The comments with "//my edit" is written by me. What is missing?
To understand for you how the motor functions, here are some informations.
Target Instruction Type Motor Operand Checksum
address Number Nr. Byte3Byte2Byte1Byte0
$01 $02 $00 $00 $00 $00 $04 $b0 $b8
Hex(04B0)=DEC(1200)
So The Motor would move in left position to 1200.