In this start up guide you get explained how to connect your Raspberry Pi 3 or 2 for the basic operation of the TMC5130-EVAL board. It will use the internal Motion Controller and +3V3 logic supply for the TMC5130. The wiring will be limited to the basic functionallity to communicate via SPI. The internal CLK for the TMC5130 will be used respective the CLK16 pin (Shown on figure 1) has to be tied to GND. The SPI CLK frequency of the Raspberry Pi will be set up to be 1MHz.

Preparation

With a fresh installation of Raspbian (In this tutorial Raspbian Jessy Lite – Version March 2017 – Release date 2017-03-02) first update the libraries:

Update packages

Shell

1

2

3

sudo apt-getupdate

sudo apt-getdist-upgrade

This may take a while since it will upgrade all packages that are installed to the newest version if available. Furthermore it will upgrade dependencies or remove them if they have been replaced with other dependencies.

Download and install the bcm2835 library. Note XXX is a place holder for the latest version. For this guide version “1.52” was used. In this case XXX is replaced by “1.52”. You can check the latest version by scrolling to the bottom of the following page: http://www.airspayce.com/mikem/bcm2835/

Download and make bcm2835 for SPI usage

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-XXX.tar.gz

gunzip bcm2835-XXX.tar.gz

tar xvf bcm2835-XXX.tar

cdbcm2835-XXX

./configure

make

sudo makecheck//Thisshould show youapass message

sudo makeinstall

Afterwards restart your PI by typing.

Restart PI

Shell

1

sudo reboot-h0

Wiring

The wiring is very simple. You will need 8 jumper wires. As a reference you can use the TMC5130-Eval_v15_01_Schematic.pdf. You will find the signals that are on each pin.

Please note that the TMC5130-EVAL has to be powered with the supply voltage e.g. 24V. To avoid damage only disconnect or connect a motor without supply voltage.

Raspberry Pi Code

An example code to initialize the TMC5130 is shown below. It will clear the reset flag in the GCONF register, sets example chopper configurations and sets the run and hold current for the motor. Furthermore it will set the ramping mode to velocity mode, an acceleration and a velocity. Be aware that the motor runs as soon as you execute the script.
You can download the code directly with your pi by typing:

Download the program file

Shell

1

wget http://blog.trinamic.com/wp-content/uploads/2017/04/spi-5130.c

C++

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

#include <bcm2835.h>

#include <stdio.h>

intmain(intargc,char**argv)

{

bcm2835_init();

bcm2835_spi_begin();

bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);// The default

bcm2835_spi_setDataMode(BCM2835_SPI_MODE3);// The default

bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256);// The default

bcm2835_spi_chipSelect(BCM2835_SPI_CS0);// The default

bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0,LOW);// the default

// Send 5 byte to the slave and simultaneously read a byte back from the slave

Yes, I am working on that. I have trouble finding the complete pinout diagram for the rs485 connector of the module. In the hardware manual only the DATA+ (pin 7), DATA- (pin 2) and POWER(GND) (pin 3) are mentioned.

Hi, that is correct. The TMCM-6110 comes with a 2-wire RS-485 interface (Half-Duplex).
Furthermore it seems that you will need additional RS-485 transceiver Hardware for the Pi. You’ll find ready to use modules / addons but could develop your own electronic as well.
I could think of using a USB to RS-485 converter connected to the Raspberry Pi as well. Sureley depends on the compatibility of the drivers but might be worth a try.

Currently we do not have code examples available for python but this is a good idea for a future blog post.
The end-stop detection is mainly dependent on the stallGuard2 feature. First a SPI communication to the chip is necessary. After that you can configure the responsible registers fitting for your needs.

Below a screen capture on youtube that shows the necessary steps when using our GUI – TMCL IDE and the TMC5130-EVAL-KIT.https://youtu.be/exlx1mW2lP4

could someone explain to me how I can convert a number like 512000 into the 4 Sequences I need for the SPI transfer.
I´m programming in C and I have no idea how to do this. It should be automatically converted in my program for example for Xtarget.

This is a simple conversion from decimal to hexadecimal. 512000 dec equals 7D000 in hex. This can either be done by your own functions or I am sure you’ll find functions on the web that can be easily implemented.

The datagram length of the SPI communication with the TMC5130 is 40 bit. As SPI in most cases work with 8 bit respective 1 byte the 40 bit are seperated into these sequences.

You can use the same example that is been used for the TMC5130. As the TMC2130 is driven via external STEP/DIR you need to have a source to provide the step signal and the direction signal from a output pin of the RasPi.

You can use the TMC2130 datasheet for further information on the register settings.