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:
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.
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.
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.
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 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
For V2 firmware we want to move all to use SPI.h library for better compatibility of different parts.
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:
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:
Otherwise pins get initialized twice what maybe doesn't matter but better if not.
Looking forward for Repetier V2
Stefan
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)
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:
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:
- 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 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.
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
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.
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());