Stepper Motor Control (Trinamic Motor)

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.
for (int i = 0 ; i < 9 ; i++)
  Serial3.write (TxBuffer[i]) ;

It doesn't work! I have been doing research for other solutions and I think it still doesn't work because I need the MAX3323 transceiver.

But before I'm going to buy the transceiver I would like to know if I really need to buy it or if it is already included in the arduino.

Thx.

No the MAX chip is not in the Arduino. You must buy one separately. I don't know of any Arduino boards that have it built-in. 80% of my custom PCBs have one of the MAX chips on them.

I have RS232 buffers on some of my 1284P boards for buffering the 2nd hardware serial port.

Bobuino2

Builds on the original Bobuino, makes USB/Serial easier to assemble, adds lots of connection options besides just shields - signal/power/ground available at each pin location. Here it is fully decked out with screw terminals and onboard FTDI Module, and with no screw terminals and an offboard FTDI module. SD card with 74HC4050 SPI buffering, MAX3232 for RS232 on Serial 2, battery backd DS1307 with 32.786 KHz crystal.

http://www.crossroadsfencing.com/BobuinoRev17/

I bought and connected the MAX232 to my arduino like here: Der Pegelumsetzer MAX232: Elektronik-Magazin

and now, it works!

Thank you all!!!!