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":
<a rel="nofollow" target="
blank">#ifdef</a> 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);
<a rel="nofollow" target="blank">#endif</a>
### 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