SkillAgentSearch skills...

TMC2208Stepper

No description available

Install / Use

/learn @teemuatlut/TMC2208Stepper
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

This library has been superseded by the newer TMCStepper library which supports many more of the Trinamic stepper drivers and more MCU architectures.

TMC2208Stepper

Arduino library for Trinamic TMC2208 Stepper driver

Table of contents

Wiring

Visual guide (imgur.com).

With Watterott SilentStepStick2208 TMC2208 powered stepper drivers with UART single wire interface, first make a solder bridge across J2 near PDN_UART pin located in the middle of the driver.

To write to the driver, connect the microcontroller TX line to PDN_UART.

To allow both writing and reading with the driver, connect microcontroller RX to PDN_UART and connect microcontroller TX to RX with a 1kOhm resistor.

Image by Watterott

hw-connection

Example

#define EN_PIN    13 								// LOW: Driver enabled. HIGH: Driver disabled
#define STEP_PIN  54 								// Step on rising edge

#include <TMC2208Stepper.h>							// Include library
TMC2208Stepper driver = TMC2208Stepper(&Serial);	// Create driver and use
													// HardwareSerial0 for communication

void setup() {
	Serial.begin(115200);							// Init used serial port
	while(!Serial);									// Wait for port to be ready

	// Prepare pins
	pinMode(EN_PIN, OUTPUT);
	pinMode(STEP_PIN, OUTPUT);

	driver.pdn_disable(1);							// Use PDN/UART pin for communication
	driver.I_scale_analog(0);						// Adjust current from the registers
	driver.rms_current(500);						// Set driver current 500mA
	driver.toff(0x2);								// Enable driver

	digitalWrite(13, LOW);							// Enable driver
}

void loop() {
	digitalWrite(STEP_PIN, !digitalRead(STEP_PIN)); // Step
	delay(10);
}

Writing to a register

Writing to a register will update the shadow register held by the library and then push the result to the driver.

uint32_t my_ihold_irun = 0x140C; // Set IRUN to 20 (DEC) and IHOLD to 12 (DEC)
driver.IHOLD_IRUN(my_ihold_irun);

Reading from a register

Writing to a register will return a boolean value indicating whether the CRC was valid. You need to give the function an address to the 32bit variable into which the function will store the response.

uint32_t data;
driver.DRV_STATUS(&data);
Serial.println(data, BIN);

Using the functions

All functions to Read and Write and Write-only registers provide both Read and Write capabilities. If the register is Write-only, the value will be read from a shadow register held by the library. Read functions to Read registers will read the register value and then bit mask and bit shift it for you. All non-helper functions write the given bit pattern to the register.

driver.tbl(0b10); // Is the same as...
driver.tbl(2);    // And will set the blank time to 32
// Read value from register
uint8_t my_blank_time = driver.tbl();

Helper functions

Function | Description ------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ void rms_current(<br>uint16_t<br>float<br>float<br>) | Set motor RMS current<br>Arguments:<br>uint16_t current_rms<br><i>Optional:</i><br>float hold current multiplier (default=0.5)<br>float sense resistor value (default=0.11) uint16_t rms_current() | Reads rms_current based on the register settings void setCurrent(<br>uint16_t<br>float<br>float<br>) | (legacy)<br>Same as rms_current but rsense and hold current arguments<br>are switched. No defaults so requires all three parameters. uint16_t getCurrent() | Read back the user input value<br>for rms_current() or setCurrent() void microsteps(uint16_t) | [0..256] Set number of microsteps bool checkOT() | Read otpw flag from DRV_STATUS register and return the result.<br>Also store the result in variable held by the library. bool getOTPW() | Return the flag value set by checkOT() void clear_otpw() | Clear the flag held by the libarary

RW: GCONF

Function | Description ----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bool GCONF(uint32_t *) | Read GCONF register void GCONF(uint32_t) | Write to the GCONF register void I_scale_analog(bool) | (Reset default=1)<br> 0: Use internal reference derived from 5VOUT<br> 1: Use voltage supplied to VREF as current reference void internal_Rsense(bool) | (Reset default: OTP)<br> 0: Operation with external sense resistors<br> 1: Internal sense resistors. Use current supplied into VREF as reference<br> for internal sense resistor. VREF pin internally is driven to GND in this mode. void en_spreadCycle(bool) | (Reset default: OTP)<br> 0: stealthChop PWM mode enabled (depending on velocity thresholds).<br> Initially switch from off to on state while in stand still, only.<br> 1: spreadCycle mode enabled void shaft(bool) | 1: Inverse motor direction void index_otpw(bool) | 0: INDEX shows the first microstep position of sequencer<br> 1: INDEX pin outputs overtemperature prewarning flag (otpw) instead void index_step(bool) | 0: INDEX output as selected by index_otpw<br> 1: INDEX output shows step pulses from internal pulse generator (toggle upon each step) void pdn_disable(bool) | 0: PDN_UART controls standstill current reduction<br> 1: PDN_UART input function disabled. Set this bit, when using the UART interface! void mstep_reg_select(bool) | 0: Microstep resolution selected by pins MS1, MS2<br> 1: Microstep resolution selected by MSTEP register void multistep_filt(bool) | (Reset default=1)<br> 0: No filtering of STEP pulses<br> 1: Software pulse generator optimization enabled when fullstep<br> frequency > 750Hz (roughly). TSTEP shows filtered step time values when active.

R+WC: GSTAT

Function | Description ----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void GSTAT(uint32_t) | Write to GSTAT register bool GSTAT(uint32_t*) | Read GSTAT register void reset(bool) | 1: Indicates that the IC has been reset since the last<br> read access to GSTAT. All registers have been cleared to reset values. void drv_err(bool) | 1: Indicates, that the driver has been shut down due to<br> overtemperature or short circuit detection since the last read access. Read DRV_STATUS<br> for details. The flag can only be cleared when all error conditions are cleared. void uv_cp(bool) | 1: Indicates an undervoltage on the charge pump. The<br> driver is disabled in this case. This flag is not latched and thus does not need to be cleared.

R: IFCNT

Function | Description ----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- bool IFCNT(uint32_t*) | Interface transmission counter. This register becomes<br> incremented with each successful UART interface write access. Read out to check the serial<br> transmission for lost data. Read accesses do not change the content.<br> The counter wraps around from 255 to 0.

W: SLAVECONF

Function | Description ----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void SLAVECONF(uint32_t) | Write register bool SLAVECONF(uint32_t*) | Read register void senddelay(uint8_t) | SENDDELAY for read access (time until reply is sent):<br> 0, 1: 8 bit times<br> 2, 3: 38 bit times<br> 4, 5: 58 bit times<br> 6, 7: 78 bit times<br> 8, 9: 98 bit times<br> 10, 11: 11*8 bit times<br> 12, 13

Related Skills

View on GitHub
GitHub Stars75
CategoryDevelopment
Updated4mo ago
Forks23

Languages

C++

Security Score

92/100

Audited on Nov 21, 2025

No findings