Teensy 3.6 - SPI controlled TMC2130 driver

Status
Not open for further replies.

vfxwolf

Well-known member
Folks,

I had the TMC 2100 driver working fine with my project, using simple Step and Dir pins and the excellent TeensyStep library. I've just received TMC2130 drivers and want to use them instead. They are controlled via SPI, and I'm having a devil of a time getting them to work.

I feel like I'm missing something. This is the basic example sketch that comes with the TMC2130Stepper library. I've got the SDO and SDI pins from the driver connected to pins 12 and 11 on the Teensy respectively, the SCK connected to pin 13, the CS to Pin 10. Step and Dir pins are connected. I get output on the Serial, but the motor does nothing.

Code:
/** * Author Teemu Mäntykallio
 * Initializes the library and turns the motor in alternating directions.
*/


#define EN_PIN    6  // Nano v3:	16 Mega:	38	//enable (CFG6)
#define DIR_PIN   3  //			19			55	//direction
#define STEP_PIN  4  //			18			54	//step
#define CS_PIN    10  //			17			64	//chip select


bool dir = true;


#include <TMC2130Stepper.h>
TMC2130Stepper driver = TMC2130Stepper(EN_PIN, DIR_PIN, STEP_PIN, CS_PIN);


void setup() {
	Serial.begin(9600);
	while(!Serial);
	Serial.println("Start...");
	driver.begin(); 			// Initiate pins and registeries
	driver.rms_current(600); 	// Set stepper current to 600mA. The command is the same as command TMC2130.setCurrent(600, 0.11, 0.5);
	driver.stealthChop(1); 	// Enable extremely quiet stepping
	
	digitalWrite(EN_PIN, LOW);
}


void loop() {
	digitalWrite(STEP_PIN, HIGH);
	delayMicroseconds(3);
	digitalWrite(STEP_PIN, LOW);
	delayMicroseconds(3);
	uint32_t ms = millis();
	static uint32_t last_time = 0;
	if ((ms - last_time) > 2000) {
		if (dir) {
			Serial.println("Dir -> 0");
			driver.shaft_dir(0);
		} else {
			Serial.println("Dir -> 1");
			driver.shaft_dir(1);
		}
		dir = !dir;
		last_time = ms;
	}
}
 
FYI, I just got a TMC2130 SilentStepStick and was able to get it to work with that example code on a Teensy 3.5 and a NEMA17 motor. I didn't have to do anything special. I used the same SPI pins as in the above description. I connected VIO to 3.3V out from the Teensy. You'll get the same output on the serial even if the TMC2130 board is removed - there's no diagnostics or anything to confirm communication with it.

Like other 3-5V SilentStepSticks, you must power the Teensy from motor power, not USB (or else make sure never to turn off motor power while connected to USB). I used a 7805 to drop from 12V motor voltage to feed the Teensy Vin. You have to either cut the USB power trace on the bottom of the Teensy, or cut the power line in the USB cable. If you don't do that, you'll blow the driver...
 
Last edited:
One other thing about that code, it uses `driver.shaft_dir(0|1)` to change the direction via SPI. The DIR_PIN is not actually used. But it still works, you can substitute `digitalWrite(DIR_PIN, LOW|HIGH)`, so you can use it with AccelStepper etc.
 
Status
Not open for further replies.
Back
Top