Problem with TMC2130 and SPI

Hey guys,
I am struggling getting my TMC2130 drivers working on my self developed "PilotBoard". It's based on an SAM3X8E so to make it short: It's an Due with 5x TMC2130 drivers onboard.

To make some things clear in the beginning:
  • I tested all components on my board first separately to make sure they are all working: EEPROM via I2C works, TMC2130s via SPI are working
  • So I started configure Repetier Firmware and connect via Repetier Host to make sure the Firmware is at least sending something
  • I didn't enable TMC2130 feature and firmware was not responding. After changing line 130 and 131 in HAL.cpp from TWI1 to TWI0 for EEPROM Repetier Host connected and responded and was able to read data from EEPROM. BTW a configuration feature for TWI0 or TWI1 would be nice so one doesn't have to change firmware!
  • In the next step I enabled TMC2130 feature and tried to connect. Repetier Host was not receiving anything. So I expect Repetier Firmware to stop initialization when communication with TMC2130 doesn't work. That's my current problem now.
As other Arduino sketches work to configure the drivers I am pretty sure there is no hardware problem. Furthermore I routed PCK1 of SAM3X8E to the TMC2130 clock inputs. TMC2130 won't respond to SPI if there is no clock signal or clk is not connected to GND instead (it will put MISO line low the whole CS LOW time). So for the moment I put the following code in Repetier.ino before "Printer::setup();":
    REG_PIOA_PDR |= 0x01000000;        // enable peripheral control
    REG_PIOA_PER &= ~0x01000000;        // Prevents disabling peripheral control of the pin
    REG_PIOA_ABSR |= 0x01000000;       // B preipherial select
  
    REG_PMC_SCER |= 0x200;
    PMC->PMC_PCK[1] = 0x01;       // master clock = 12Mhz (crystal freq)

To make sure the drivers have this signal. Measuring the signal with an oscilloscope confirms the signal is working at 12MHz. That shouldn't be the problem either. To make absolutely sure it's not a clk problem I connected a SilentStepStick TMC2130 (Watterott) to my board headers (it has the clk input connected to GND what is mostly the standard). I reconfigured the pins of SilentStepStick in my files to be my "X" driver (it's the first one getting initialized). The result was the same as before.

So next thing I did is connecting a logic-analyzer to my SPI bus and the CS pin of motor X (as it's the first one getting initialized):


Obviously here's the problem. Taking a look at channel0 shows the SPI's clock line is doing something strange. Sure it's an software SPI but taking channel3 into consideration shows that the amount of falling edges of the clock line differs from CS LOW cycle to CS LOW cycle. As MISO generates different signals I assume the driver is responding somehow.

As a very unlikely reason I could imagine that the counter used for generating PCK1 is used by SPI. Nevertheless I am pretty sure that's not the problem. But I am going to deactivate this feature and connect the SilentStepStick again.

Regarding "#define SDSS 77" I am not sure what to do. I also tried several combinations trying other configurations like "#define NONSTANDARD_SDSS". (Pin configurations at the end of this post)

Does anyone has an idea what the problem might be? I would be super thankful for any help!

Best regards
Stefan

PS: A nice configuration feature for the DEV version of Repetier would be to set the proper Sense Resistor value for TMC2130. Standard is 0.11Ohm for the SilentStepStick TMC2130. Clones or other boards may have other sense resistors. Function:
tmc_driver->rms_current(level);
in Commands.cpp line 533 assumes the sense resistor to be 0.11Ohm. Mine is currently 0.1Ohm so current calculation of function rms_current() is not exact in my case. 
Changing it to "tmc_driver->rms_current(level, 0.5, 0.1);" does pretty much the same but taking the sense resistor into account. The value "0.5" stands for the hold current multiplier. Being able to set this value in the firmware configuration would be great as well.

Here is my userpins.h file:
//Definition der individuellen Pins für das PilotBoard 4.0 REV 1

#define MOSI_PIN 75
#define MISO_PIN 74
#define SCK_PIN 76
//#define SDSSORIG 52
#define SDSS   77
//#define NONSTANDARD_SDSS 1

#define ORIG_X_STEP_PIN 46
#define ORIG_X_DIR_PIN 44
#define ORIG_X_ENABLE_PIN 45
#define ORIG_X_MIN_PIN   -1
#define ORIG_X_MAX_PIN     12

/*#define ORIG_Y_STEP_PIN 50
#define ORIG_Y_DIR_PIN 48
#define ORIG_Y_ENABLE_PIN 49
#define ORIG_Y_MIN_PIN       11
#define ORIG_Y_MAX_PIN       -1*/
#define ORIG_Y_STEP_PIN 40
#define ORIG_Y_DIR_PIN 39
#define ORIG_Y_ENABLE_PIN 38
#define ORIG_Y_MIN_PIN       11
#define ORIG_Y_MAX_PIN       -1

#define ORIG_Z_STEP_PIN 64
#define ORIG_Z_DIR_PIN 63
#define ORIG_Z_ENABLE_PIN 62
#define ORIG_Z_MIN_PIN       28
#define ORIG_Z_MAX_PIN       -1

#define ORIG_E0_STEP_PIN 25
#define ORIG_E0_DIR_PIN 26
#define ORIG_E0_ENABLE_PIN 24

/*#define ORIG_E1_STEP_PIN 40
#define ORIG_E1_DIR_PIN 39
#define ORIG_E1_ENABLE_PIN 38*/

#define ORIG_PS_ON_PIN       -1

#define PCK1    55 //PCK1 pin

#define HEATER_0_PIN   9 //Extruder 1
#define HEATER_1_PIN   2   //Heizbett
#define HEATER_2_PIN   3   //Extruder 2

#define TEMP_0_PIN     2 //Extruder 1
#define TEMP_1_PIN     1   //Heizbett (Pin muss nach Port lt. Datenblatt des SAM3X gewählt werden: Heibzett Thermistor = Due Pin 60 = Due Analog In 6 = PA3 = SAM3X AD1)
#define TEMP_2_PIN     3 //Extruder 2
#define TEMP_3_PIN     0 //Steuerplatine

#define ORIG_FAN_PIN   8 //Bauteilkuehler 
#define ORIG_FAN2_PIN       6 //Steuerplatinenluefter

#define E0_PINS ORIG_E0_STEP_PIN,ORIG_E0_DIR_PIN,ORIG_E0_ENABLE_PIN,
#define E1_PINS ORIG_E1_STEP_PIN,ORIG_E1_DIR_PIN,ORIG_E1_ENABLE_PIN,

#define LED_PIN   13

// 20 or 70
#define SDA_PIN 70
// 21 or 71
#define SCL_PIN 71

#define TWI_CLOCK_FREQ           400000
// see eeprom device data sheet for the following values, these are for 24xx256
#define EEPROM_SERIAL_ADDR     0x50   // 7 bit i2c address (without R/W bit)
#define EEPROM_PAGE_SIZE       64     // page write buffer size
#define EEPROM_PAGE_WRITE_TIME   7      // page write time in milliseconds (docs say 5ms but that is too short)
// TWI_MMR_IADRSZ_1_BYTE for 1 byte, or TWI_MMR_IADRSZ_2_BYTE for 2 byte
#define EEPROM_ADDRSZ_BYTES     TWI_MMR_IADRSZ_2_BYTE
#define EEPROM_AVAILABLE 1

And part of my Configuration.h:
#define TMC2130_X_CS_PIN 47
#define TMC2130_Y_CS_PIN 41
#define TMC2130_Z_CS_PIN 65
#define TMC2130_EXT0_CS_PIN 23
#define TMC2130_EXT1_CS_PIN -1
#define TMC2130_EXT2_CS_PIN -1

Comments

  • PCK1 seems not to be the problem. I deactivated it and used the SilentStepStip TMC2130. Still the same result. 
    I also used a regular Arduino Due and connected the SilentStepStip TMC2130 to it. Still the same result on the SPI bus. There must be some #define 's missing or be wrong in my configuration ?!
  • You should browse the forum for the thread form the one who added the 2130 support. I think it contains some informations that would be useful. Have no 2130 so no experience here, but I think he used software SPI. Hardware SPI with V1 firmware is a pain as we use a own SPI library while 2130 library will most likely use the SPI.h library from arduino and then the SPI modes etc can make big trouble.

    For V2 firmware we want to move all to use SPI.h library for better compatibility of different parts.
  • I read the whole thread including the one on Git. I am going to participate a bit int the code project as I was working on this stuff for while anyway.
    I solved the problem in the meanwhile. The problem was the first driver was initialized properly, but when the second driver was initialized and its driver function "tmc_driver->begin()" was called the software stuck. After hours I found out that this part in the file "TMC2130Stepper.cpp" was the reason:

    #ifdef TMC2130DEBUG
    Serial.println("TMC2130 Stepper driver library");
    Serial.print("Enable pin: ");
    Serial.println(_pinEN);
    Serial.print("Direction pin: ");
    Serial.println(_pinDIR);
    Serial.print("Step pin: ");
    Serial.println(_pinSTEP);
    Serial.print("Chip select pin: ");
    Serial.println(_pinCS);
    #endif

    I couldn't even make out where TMC2130DEBUG was defined. And I have no reason why this was the reason to stuck.  

    It's also a good shot to comment out these lines in the same file:
    pinMode(_pinEN, OUTPUT);
    pinMode(_pinDIR, OUTPUT);
    pinMode(_pinSTEP, OUTPUT);

    digitalWrite(_pinEN, HIGH); //deactivate driver (LOW active)
    digitalWrite(_pinDIR, LOW); //LOW or HIGH
    digitalWrite(_pinSTEP, LOW);

    Otherwise pins get initialized twice what maybe doesn't matter but better if not.

    Looking forward for Repetier V2

    Stefan
  • @stefanokolos First of all, sorry for the late reply. Thanks to @Repetier for pointing out this issue to me.

    I will try to go very carefully over all the details you provided, but right away something stand out:

    The current version of the firmware was only tested with hardware SPI. That is, the SPI lines of the drivers should go to the SPI header (ICSP) on the Due and only the CS lines are freely selectable. Your MISO_PIN, MOSI_PIN, SCK_PIN values are different than the standard Due SPI pins (MISO = 108, MOSI = 109, SCK =110). The undelying TMC library has only recently added support for software SPI, but that has neither been incorporated in Repetier nor tested.

    If it's possible, can you also test with the SPI lines wired to the hardware SPI pins on the DUE?

    Also, can you post a schematic of your board? (assuming it's opensource)
  • Hey alexsomesan,

    sorry for the very late reply. In the meanwhile my board is working. There were a couple of issues that combined to one big problem in the beginning. For those having similar problems, please read this post carefully:
    • The screenshot in my first post was completely wrong. The TMC2130 library uses a Baudrate of 2MHz while my logic analyzer's the sampling rate was about 1MHz. So the communication was completely nonsense but the real reason was my PCK1 line (that's a 12MHz clock output I connected to the TMC2130 driver on my custom board. This is optional, e.g. a SilentStepStick TMC2130 doesn't need this)
    • To make some things clear for other people struggling with the pin assignments of the Due (I don't want to be a wisenheimer but it can be pretty confusing for those people who don't want to spend hours). The next couple bullet-points should make things clear:
    • There is an ICSP header on the Due but it regards to the 16U2 chip that interfaces the SAM3X8E programming port. The Due itself doesn't have an ICSP header as it has an built-in bootloader called SAM-BA. The Due's SPI pins are on the SPI header.
    • To make the pin assignment a little bit more clear: alexsomesan you're right regarding the physical pins of the SAM3X8E LQFP-144 package. These are 108, 109 & 110 for the SPI lines. But these pin numbers doesn't help for programming. There is a pin mapping for the Due which maps the port pins (e.g. PA20) to a pin number that can be used in the code. The mapping is available here: https://www.arduino.cc/en/Hacking/PinMappingSAM3X  
    • To find out the port pin the Due schematics can be used: https://www.arduino.cc/en/uploads/Main/arduino-Due-schematic.pdf. Regarding alexsomesan's post: e.g. MISO is on physical pin 108 which is PA25 which is number 74 for use in your code. If you are going to use HW SPI you don't need to specify any MISO, MOSI or SCK pins.
    • Therefore I was already using HW SPI lines.

    Here is a short description for those who want to modify the firmware for their needs:

    ### SW or HW SPI configuration
    If someone doesn't want to use those HW SPI lines but the SW SPI lines instead he has to make some minor changes:
    • #define MISO, MOSI, SCK as well as your CS lines in "Configuration.h" or "userpins.h" if you are using a custom board. (CS lines can be be defined in Repetier's  graphical configuration tool from version 1.0.1dev on.
    • Open Repetier's file "Printer.cpp" and go to line 1132 or so and find:
    #if TMC2130_ON_X
        Printer::tmc_driver_x = new TMC2130Stepper(X_ENABLE_PIN, X_DIR_PIN, X_STEP_PIN, TMC2130_X_CS_PIN);
        configTMC2130(Printer::tmc_driver_x, TMC2130_STEALTHCHOP_X, TMC2130_STALLGUARD_X,
        TMC2130_PWM_AMPL_X, TMC2130_PWM_GRAD_X, TMC2130_PWM_AUTOSCALE_X, TMC2130_PWM_FREQ_X);
    #endif
    • change the line "... = new TMC2130Stepper(....." to "... = new TMC2130(...., TMC2130_X_CS_PIN, MOSI_PIN, MISO_PIN, SCK_PIN)"
    • From then the library's SW SPI is used. I didn't test it but it should work.
    Don't forget to make the same changes for the other drivers.


    ### Custom driver configuration
    If you need to make more configurations for the drivers go to the very end of the "Printer.cpp" file and add your desired lines there. There is an API-description of the available functions in the file "Readme.md" of the TMC2130 library's project.


    ### Different sense-resistors
    If your drivers doesn't have 0.11Ohm sense-resistors (Standard for SilentStepStick TMC2130) the current defined in "Configuration.h" won't be right. Therefore go to file "Commands.cpp" to line 533 and find "tmc_driver->rms_current(level);". Then change it to e.g. "tmc_driver->rms_current(level, 0.5, 0.1);". The parameter 0.5 is the multiple of your run-current as hold-current, in this case 50% of the run-current. 0.1 is the sense-resistor value.


    ### Clock line output from SAM3X8E to the drivers
    I am probably the only one needing the clock line (in my case PCK1) to run the drivers. Everyone using e.g. SilentStepStick TMC2130 drivers won't have to think about this issue so I skip explanation. Otherwise let me know, there are only a few lines of code needed to get it working.


    ### Firmware seems to stuck / No communication
    If someone is having the issue that the firmware seems to stuck completely, open the TMC2130 library and comment out the following lines in file "TMC2130Stepper.cpp":

    #ifdef TMC2130DEBUG
    Serial.println("TMC2130 Stepper driver library");
    Serial.print("Enable pin: ");
    Serial.println(_pinEN);
    Serial.print("Direction pin: ");
    Serial.println(_pinDIR);
    Serial.print("Step pin: ");
    Serial.println(_pinSTEP);
    Serial.print("Chip select pin: ");
    Serial.println(_pinCS);
    #endif

    ### A little bit more control and info about the TMC2130 drivers:
    I know it's quick and dirty and shouldn't be used during printing but for those desiring some more status information about the drivers can also add the following lines to their "Commands.cpp" file (roundabout line 2850, after the "break;"):
    Note: Maybe these two commands will be used for other things in the future. I implemented it quick and dirty, so no guarantee! But if you want to tune your RMS current or something these two commands will help you.

    //Code by Stefan Wiedemann
        case 916: // Set individual motor current on Trinamic TMC2130
            Com::printF(PSTR("Trinamic motor current setting:"));
            Com::println();
            if(com->hasNoXYZ() && !com->hasE()) {
    #if TMC2130_ON_X
                Com::printF(PSTR(" X: I_RMS: "), Printer::tmc_driver_x->rms_current());
                Com::printF(PSTR(", I_HOLD: "), Printer::tmc_driver_x->hold_current());
                Com::printF(PSTR(", HOLD_DELAY: "), Printer::tmc_driver_x->hold_delay());
                Com::printF(PSTR(", R_SENSE: "), Printer::tmc_driver_x->Rsense);
                Com::println();
    #endif
    #if TMC2130_ON_Y
                Com::printF(PSTR(" Y: I_RMS: "), Printer::tmc_driver_y->rms_current());
                Com::printF(PSTR(", I_HOLD: "), Printer::tmc_driver_y->hold_current());
                Com::printF(PSTR(", HOLD_DELAY: "), Printer::tmc_driver_y->hold_delay());
                Com::printF(PSTR(", R_SENSE: "), Printer::tmc_driver_y->Rsense);
                Com::println();
    #endif
    #if TMC2130_ON_Z
                Com::printF(PSTR(" Z: I_RMS: "), Printer::tmc_driver_z->rms_current());
                Com::printF(PSTR(", I_HOLD: "), Printer::tmc_driver_z->hold_current());
                Com::printF(PSTR(", HOLD_DELAY: "), Printer::tmc_driver_z->hold_delay());
                Com::printF(PSTR(", R_SENSE: "), Printer::tmc_driver_z->Rsense);
                Com::println();
    #endif
    #if TMC2130_ON_EXT0
                Com::printF(PSTR(" E0: I_RMS: "), Printer::tmc_driver_e0->rms_current());
                Com::printF(PSTR(", I_HOLD: "), Printer::tmc_driver_e0->hold_current());
                Com::printF(PSTR(", HOLD_DELAY: "), Printer::tmc_driver_e0->hold_delay());
                Com::printF(PSTR(", R_SENSE: "), Printer::tmc_driver_e0->Rsense);
                Com::println();
    #endif
    #if TMC2130_ON_EXT1
                Com::printF(PSTR(" E1: I_RMS: "), Printer::tmc_driver_e1->rms_current());
                Com::printF(PSTR(", I_HOLD: "), Printer::tmc_driver_e1->hold_current());
                Com::printF(PSTR(", HOLD_DELAY: "), Printer::tmc_driver_e1->hold_delay());
                Com::printF(PSTR(", R_SENSE: "), Printer::tmc_driver_e1->Rsense);
                Com::println();
    #endif
    #if TMC2130_ON_EXT2
                Com::printF(PSTR(" E2: I_RMS: "), Printer::tmc_driver_e2->rms_current());
                Com::printF(PSTR(", I_HOLD: "), Printer::tmc_driver_xe2>hold_current());
                Com::printF(PSTR(", HOLD_DELAY: "), Printer::tmc_driver_e2->hold_delay());
                Com::printF(PSTR(", R_SENSE: "), Printer::tmc_driver_e2->Rsense);
                Com::println();
    #endif
              //Com::println();
            }
    #if TMC2130_ON_X
            if(com->hasX() && com->hasI() && com->hasH() && com->hasR()) {
                Com::printF(PSTR(" X: "));
                Com::printF(PSTR("I:"), (uint16_t) com->I);
                Com::printF(PSTR(", H:"), (float) com->H);
                Com::printF(PSTR(", R:"), (float) com->R);
                Com::println();
                Printer::tmc_driver_x->rms_current((uint16_t)(com->I), (float)(com->H), (float)(com->R));
            }
    #endif
    #if TMC2130_ON_Y
            if(com->hasY() && com->hasI() && com->hasH() && com->hasR()) {
                Com::printF(PSTR(" Y: "));
                Com::printF(PSTR("I:"), (uint16_t) com->I);
                Com::printF(PSTR(", H:"), (float) com->H);
                Com::printF(PSTR(", R:"), (float) com->R);
                Com::println();            
                Printer::tmc_driver_y->rms_current((uint16_t)(com->I), (float)(com->H), (float)(com->R));
            }
    #endif
    #if TMC2130_ON_Z
            if(com->hasZ() && com->hasI() && com->hasH() && com->hasR()) {
                Com::printF(PSTR(" Z: "));
                Com::printF(PSTR("I:"), (uint16_t) com->I);
                Com::printF(PSTR(", H:"), (float) com->H);
                Com::printF(PSTR(", R:"), (float) com->R);
                Com::println();                    
                Printer::tmc_driver_z->rms_current((uint16_t)(com->I), (float)(com->H), (float)(com->R));
            }
    #endif
    #if TMC2130_ON_EXT0
            if(com->hasE() && ((int)(com->E) == 0) && com->hasI() && com->hasH() && com->hasR()) {
                Com::printF(PSTR(" E0: "));
                Com::printF(PSTR("I:"), (uint16_t) com->I);
                Com::printF(PSTR(", H:"), (float) com->H);
                Com::printF(PSTR(", R:"), (float) com->R);
                Com::println();                    
                Printer::tmc_driver_e0->rms_current((uint16_t)(com->I), (float)(com->H), (float)(com->R));
            }
    #endif
    #if TMC2130_ON_EXT1
            if(com->hasE() && ((int)(com->E) == 1) && com->hasI() && com->hasH() && com->hasR()) {
                Com::printF(PSTR(" E1: "));
                Com::printF(PSTR("I:"), (uint16_t) com->I);
                Com::printF(PSTR(", H:"), (float) com->H);
                Com::printF(PSTR(", R:"), (float) com->R);
                Com::println();                    
                Printer::tmc_driver_e1->rms_current((uint16_t)(com->I), (float)(com->H), (float)(com->R));
            }
    #endif
    #if TMC2130_ON_EXT2
            if(com->hasE() && ((int)(com->E) == 2) && com->hasI() && com->hasH() && com->hasR()) {
                Com::printF(PSTR(" E2: "));
                Com::printF(PSTR("I:"), (uint16_t) com->I);
                Com::printF(PSTR(", H:"), (float) com->H);
                Com::printF(PSTR(", R:"), (float) com->R);
                Com::println();                    
                Printer::tmc_driver_e2->rms_current((uint16_t)(com->I), (float)(com->H), (float)(com->R));
            }
    #endif
        break;
          
          //Code by Stefan Wiedemann
         case 917: // Show driver status of Trinamic TMC2130
            Com::printF(PSTR("Trinamic driver status:"));
            Com::println();
    #if TMC2130_ON_X
            if(com->hasX()) {
                Com::printF(PSTR(" X:"));
                Com::println();
                Com::printF(PSTR("Standstill: "), Printer::tmc_driver_x->stst());
                Com::println();
                Com::printF(PSTR("Open load phase A: "), Printer::tmc_driver_x->ola());
                Com::println();
                Com::printF(PSTR("Open load phase B: "), Printer::tmc_driver_x->olb());
                Com::println();
                Com::printF(PSTR("Short to GND phase A: "), Printer::tmc_driver_x->s2ga());
                Com::println();
                Com::printF(PSTR("Short to GND phase B: "), Printer::tmc_driver_x->s2gb());
                Com::println();
                Com::printF(PSTR("Overtemperature prewarning: "), Printer::tmc_driver_x->otpw()); 
                Com::println();
                Com::printF(PSTR("Overtemperature: "), Printer::tmc_driver_x->ot()); 
                Com::println();
                Com::printF(PSTR("Stallguard2 status: "), Printer::tmc_driver_x->stallguard());
                Com::println();
                Com::printF(PSTR("Actual motor current: "), Printer::tmc_driver_x->cs_actual());    
                Com::println();
                Com::printF(PSTR("Full step active indicator: "), Printer::tmc_driver_x->fsactive());
                Com::println();
            }
    #endif
    #if TMC2130_ON_Y
            if(com->hasY()) {
                Com::printF(PSTR(" Y:"));
                Com::println();
                Com::printF(PSTR("Standstill: "), Printer::tmc_driver_y->stst());
                Com::println();
                Com::printF(PSTR("Open load phase A: "), Printer::tmc_driver_y->ola());
                Com::println();
                Com::printF(PSTR("Open load phase B: "), Printer::tmc_driver_y->olb());
                Com::println();
                Com::printF(PSTR("Short to GND phase A: "), Printer::tmc_driver_y->s2ga());
                Com::println();
                Com::printF(PSTR("Short to GND phase B: "), Printer::tmc_driver_y->s2gb());
                Com::println();
                Com::printF(PSTR("Overtemperature prewarning: "), Printer::tmc_driver_y->otpw()); 
                Com::println();
                Com::printF(PSTR("Overtemperature: "), Printer::tmc_driver_y->ot()); 
                Com::println();
                Com::printF(PSTR("Stallguard2 status: "), Printer::tmc_driver_y->stallguard());
                Com::println();
                Com::printF(PSTR("Actual motor current: "), Printer::tmc_driver_y->cs_actual());    
                Com::println();
                Com::printF(PSTR("Full step active indicator: "), Printer::tmc_driver_y->fsactive());
                Com::println();
            }
    #endif
    #if TMC2130_ON_Z
            if(com->hasZ()) {
                Com::printF(PSTR(" Z:"));
                Com::println();
                Com::printF(PSTR("Standstill: "), Printer::tmc_driver_z->stst());
                Com::println();
                Com::printF(PSTR("Open load phase A: "), Printer::tmc_driver_z->ola());
                Com::println();
                Com::printF(PSTR("Open load phase B: "), Printer::tmc_driver_x->olb());
                Com::println();
                Com::printF(PSTR("Short to GND phase A: "), Printer::tmc_driver_z->s2ga());
                Com::println();
                Com::printF(PSTR("Short to GND phase B: "), Printer::tmc_driver_z->s2gb());
                Com::println();
                Com::printF(PSTR("Overtemperature prewarning: "), Printer::tmc_driver_z->otpw()); 
                Com::println();
                Com::printF(PSTR("Overtemperature: "), Printer::tmc_driver_z->ot()); 
                Com::println();
                Com::printF(PSTR("Stallguard2 status: "), Printer::tmc_driver_z->stallguard());
                Com::println();
                Com::printF(PSTR("Actual motor current: "), Printer::tmc_driver_z->cs_actual());    
                Com::println();
                Com::printF(PSTR("Full step active indicator: "), Printer::tmc_driver_z->fsactive());
                Com::println();
            }
    #endif
    #if TMC2130_ON_EXT0
            if(com->hasE() && ((int)(com->E) == 0)) {
                Com::printF(PSTR(" E0:"));
                Com::println();
                Com::printF(PSTR("Standstill: "), Printer::tmc_driver_e0->stst());
                Com::println();
                Com::printF(PSTR("Open load phase A: "), Printer::tmc_driver_e0->ola());
                Com::println();
                Com::printF(PSTR("Open load phase B: "), Printer::tmc_driver_e0->olb());
                Com::println();
                Com::printF(PSTR("Short to GND phase A: "), Printer::tmc_driver_e0->s2ga());
                Com::println();
                Com::printF(PSTR("Short to GND phase B: "), Printer::tmc_driver_e0->s2gb());
                Com::println();
                Com::printF(PSTR("Overtemperature prewarning: "), Printer::tmc_driver_e0->otpw()); 
                Com::println();
                Com::printF(PSTR("Overtemperature: "), Printer::tmc_driver_e0->ot()); 
                Com::println();
                Com::printF(PSTR("Stallguard2 status: "), Printer::tmc_driver_e0->stallguard());
                Com::println();
                Com::printF(PSTR("Actual motor current: "), Printer::tmc_driver_e0->cs_actual());    
                Com::println();
                Com::printF(PSTR("Full step active indicator: "), Printer::tmc_driver_e0->fsactive());
                Com::println();
            }
    #endif
    #if TMC2130_ON_EXT1
            if(com->hasE() && ((int)(com->E) == 1)) {
                Com::printF(PSTR(" E1:"));
                Com::println();
                Com::printF(PSTR("Standstill: "), Printer::tmc_driver_e1->stst());
                Com::println();
                Com::printF(PSTR("Open load phase A: "), Printer::tmc_driver_e1->ola());
                Com::println();
                Com::printF(PSTR("Open load phase B: "), Printer::tmc_driver_e1->olb());
                Com::println();
                Com::printF(PSTR("Short to GND phase A: "), Printer::tmc_driver_e1->s2ga());
                Com::println();
                Com::printF(PSTR("Short to GND phase B: "), Printer::tmc_driver_e1->s2gb());
                Com::println();
                Com::printF(PSTR("Overtemperature prewarning: "), Printer::tmc_driver_e1->otpw()); 
                Com::println();
                Com::printF(PSTR("Overtemperature: "), Printer::tmc_driver_e1->ot()); 
                Com::println();
                Com::printF(PSTR("Stallguard2 status: "), Printer::tmc_driver_e1->stallguard());
                Com::println();
                Com::printF(PSTR("Actual motor current: "), Printer::tmc_driver_e1->cs_actual());    
                Com::println();
                Com::printF(PSTR("Full step active indicator: "), Printer::tmc_driver_e1->fsactive());
                Com::println();
            }
    #endif
    #if TMC2130_ON_EXT2
            if(com->hasE() && ((int)(com->E) == 2)) {
                Com::printF(PSTR(" E2:"));
                Com::println();
                Com::printF(PSTR("Standstill: "), Printer::tmc_driver_e2->stst());
                Com::println();
                Com::printF(PSTR("Open load phase A: "), Printer::tmc_driver_e2->ola());
                Com::println();
                Com::printF(PSTR("Open load phase B: "), Printer::tmc_driver_e2->olb());
                Com::println();
                Com::printF(PSTR("Short to GND phase A: "), Printer::tmc_driver_e2->s2ga());
                Com::println();
                Com::printF(PSTR("Short to GND phase B: "), Printer::tmc_driver_e2->s2gb());
                Com::println();
                Com::printF(PSTR("Overtemperature prewarning: "), Printer::tmc_driver_e2->otpw()); 
                Com::println();
                Com::printF(PSTR("Overtemperature: "), Printer::tmc_driver_e2->ot()); 
                Com::println();
                Com::printF(PSTR("Stallguard2 status: "), Printer::tmc_driver_e2->stallguard());
                Com::println();
                Com::printF(PSTR("Actual motor current: "), Printer::tmc_driver_e2->cs_actual());    
                Com::println();
                Com::printF(PSTR("Full step active indicator: "), Printer::tmc_driver_e2->fsactive());
                Com::println();
            }
    #endif
        break;
           
    #endif
        default:
            if(Printer::debugErrors()) {
                Com::writeToAll = false;
                Com::printF(Com::tUnknownCommand);
                com->printCommand();
            }
        }
    }


    Usage:

    M916 

    Shows I_RMS, I_HOLD, HOLD_DELAY and R_SENSE value of all TMC2130 driver


    M916 <Driver> I<uint16_t> H<float> R<float>

    Set I_RMS (I), I_HOLD (H) and R_SENSE (R) value of one or multiple drivers. 
    Example: M916 X Y Z I1200 H0.5 R0.12 (Sets a current of 1200mA and a hold current of 600mA. The sense resistor value is needed to calculate the right value to be written in the TMC2130's register. Standard for SilentStepStick TMC2130 is 0.11 Ohm. 
    Note: If you want to set multiple extruders driver you have to do this one by one. Specify extruder by E0, E1 or E2

    M917 <Driver>
    Prints the current driver status of the specified driver. Multiple driver possible. If there are multiple extruder run this command one by one.


    ------------------------------------------------------------------------------------------------------------------------------------------------

    Sorry for the very long post and the code inside the thread. I will try to merge my changes to the repetier development version after cleaning the code a little bit and making it more comfortable to implement if wanted?

    I hope this helps somebody.
    Stefan

  • stefanokolos: Did you connect a graphical LCD controller to your board? This controller is using also SPI communication lines (there is also SD card socket connected to the LCD board), so I am wondering how the LCD would work having TMC2130 step drivers connected to the board (HW SPI). 

    I am designing a shield for DUE and I added configurable polulu drivers so I plan to use TMC2130 connected to HW SPI. I am planning later to attach an ESP8266 to a serial port in order to be able to control the printer over WIFI.
  • edited December 2018
    @stefanokolo, i try to add your code to Command.cpp but give me an error during compilation (endif without if), please could you explain bettere or share your complete file?

    C:\Users\Marco\AppData\Local\Temp\arduino_build_678568\sketch\Commands.cpp: In static member function 'static void Commands::processMCode(GCode*)':

    Commands.cpp:2935:82: error: call of overloaded 'printF(const char*, uint16_t)' is ambiguous

                 Com::printF(PSTR(" X: I_RMS: "), Printer::tmc_driver_x->rms_current());

Sign In or Register to comment.