Skip to content

API_TMC2130

teemuatlut edited this page May 12, 2019 · 1 revision

TMC2130 API methods

Constructors

  • TMC2130Stepper(uint16_t pinCS, float RS = default_RS)
  • TMC2130Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK)
  • TMC2130Stepper(uint16_t pinCS, float RS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK)

Reading and writing values

Most methods have both read and write versions.

A write method takes in arguments of a certain datatype and

a read method takes in no arguments but returns a value of appropriate datatype.

Some registers are read only and therefore do not have write methods associated with them.

Public methods

Method Description
void begin() Set pin modes
Init SW SPI

Push default register values for GCONF, CHOPCONF, COOLCONF, PWMCONF and IHOLD_IRUN

Set off time = 8 and blank time = 24

void setSPISpeed(uint32_t) Set Hardware SPI speed in megahertz
void switchCSpin(bool) Toggle CS pin
bool isEnabled() Test if driver is powered by testing ENABLE pin and reading off time value
void push() Push all shadow registers held by the library to the driver
uint16_t cs2rms(uint8_t) Convert a CS number to an RMS value in milliamps
void rms_current(uint16_t) Set driver RMS current in milliamps
void rms_current(uint16_t, float) Set driver RMS current and associated hold current
uint16_t rms_current() Read back the RMS current value in milliamps
void hold_multiplier(float) Set hold multiplier [0..1] that is calculated from RMS current
float hold_multiplier() Read back hold multiplier value
uint8_t test_connection() Test connection to the driver.
Reads DRV_STATUS register and checks if value is valid (not 0x00000000 or 0xFFFFFFFF)

Helper functions

Helper methods aim to simplify interfacing with some of the configuration options in the driver. The arguments to the method are the value you want to use and the method will translate that to the correct bitpattern that corresponds with the requested setting.

Method Description
void microsteps(uint16_t) Set microstep setting
Valid values are 256, 128, 64, 32, 16, 8, 4, 2 and 0 (fullstepping)
uint16_t microsteps()
void blank_time(uint8_t) Set blank time value for spreadCycle. Doesn't affect stealthChop.
Valid values are 16, 24, 36, 54
uint8_t blank_time()
void hysteresis_end(int8_t) Set effective hysteresis end value. [-3..12]
int8_t hysteresis_end()
void hysteresis_start(uint8_t) Set effective hysteresis start value. [1..8]
uint8_t hysteresis_start()
void sg_current_decrease(uint8_t) Set stallGuard current decrease value.
Valid values are: 32, 8, 2, 1
uint8_t sg_current_decrease()

GSTAT

Method Description
void GSTAT(uint8_t) Write to GSTAT register to clear bits
uint8_t GSTAT() Read GSTAT register
bool reset() Indicates that the IC has been reset since the last read access to GSTAT.
All registers have been cleared to reset values.
bool drv_err() Indicates, that the driver has been shut down due to overtemperature
or short circuit detection since the last read access. Read DRV_STATUS for details.
The flag can only be reset when all error conditions are cleared.
bool uv_cp() Indicates an undervoltage on the charge pump. The driver is disabled in this case.

IHOLD_IRUN

Method Description
void IHOLD_IRUN(uint32_t) Write to IHOLD_IRUN to control hold and running current and
time to start ramping down to hold current
uint32_t IHOLD_IRUN() Read register
void ihold(uint8_t) Set holding current CS value [0..31]
void irun(uint8_t) Set run current CS value [0..31]
void iholddelay(uint8_t) Controls the number of clock cycles for motor power down after a motion
as soon as standstill is detected (stst=1) and TPOWERDOWN has expired.
The smooth transition avoids a motor jerk upon power down.

0: instant power down
1..15: Delay per current reduction step in multiple of 2^18 clocks

uint8_t ihold()
uint8_t irun()
uint8_t iholddelay()

TPOWERDOWN

Method Description
uint8_t TPOWERDOWN()
void TPOWERDOWN(uint8_t)

TSTEP

Method Description
uint32_t TSTEP()

TPWMTHRS

Method Description
uint32_t TPWMTHRS()
void TPWMTHRS(uint32_t)

MSCNT

Method Description
uint16_t MSCNT();

MSCURACT

Method Description
uint32_t MSCURACT()
int16_t cur_a()
int16_t cur_b()

GCONF

Method Description
uint32_t GCONF()
void GCONF(uint32_t)
void I_scale_analog(bool)
void internal_Rsense(bool)
void en_pwm_mode(bool)
void enc_commutation(bool)
void shaft(bool)
void diag0_error(bool)
void diag0_otpw(bool)
void diag0_stall(bool)
void diag1_stall(bool)
void diag1_index(bool)
void diag1_onstate(bool)
void diag1_steps_skipped(bool)
void diag0_int_pushpull(bool)
void diag1_pushpull(bool)
void small_hysteresis(bool)
void stop_enable(bool)
void direct_mode(bool)
bool I_scale_analog()
bool internal_Rsense()
bool en_pwm_mode()
bool enc_commutation()
bool shaft()
bool diag0_error()
bool diag0_otpw()
bool diag0_stall()
bool diag1_stall()
bool diag1_index()
bool diag1_onstate()
bool diag1_steps_skipped()
bool diag0_int_pushpull()
bool diag1_pushpull()
bool small_hysteresis()
bool stop_enable()
bool direct_mode()

IOIN

Method Description
uint32_t IOIN()
bool step()
bool dir()
bool dcen_cfg4()
bool dcin_cfg5()
bool drv_enn_cfg6()
bool dco()
uint8_t version()

TCOOLTHRS

Method Description
uint32_t TCOOLTHRS()
void TCOOLTHRS(uint32_t)

THIGH

Method Description
uint32_t THIGH()
void THIGH(uint32_t)

XDRIRECT

Method Description
uint32_t XDIRECT()
void XDIRECT(uint32_t)
void coil_A(int16_t)
void coil_B(int16_t)
int16_t coil_A()
int16_t coil_B()

VDCMIN

Method Description
uint32_t VDCMIN()
void VDCMIN(uint32_t)

CHOPCONF

Method Description
uint32_t CHOPCONF()
void CHOPCONF(uint32_t)
void toff(uint8_t)
void hstrt(uint8_t)
void hend(uint8_t)
//void fd(uint8_t)
void disfdcc(bool)
void rndtf(bool)
void chm(bool)
void tbl(uint8_t)
void vsense(bool)
void vhighfs(bool)
void vhighchm(bool)
void sync(uint8_t)
void mres(uint8_t)
void intpol(bool)
void dedge(bool)
void diss2g(bool)
uint8_t toff()
uint8_t hstrt()
uint8_t hend()
//uint8_t fd()
bool disfdcc()
bool rndtf()
bool chm()
uint8_t tbl()
bool vsense()
bool vhighfs()
bool vhighchm()
uint8_t sync()
uint8_t mres()
bool intpol()
bool dedge()
bool diss2g()

COOLCONF

Method Description
void COOLCONF(uint32_t)
uint32_t COOLCONF()
void semin(uint8_t)
void seup(uint8_t)
void semax(uint8_t)
void sedn(uint8_t)
void seimin(bool)
void sgt(int8_t)
void sfilt(bool)
uint8_t semin()
uint8_t seup()
uint8_t semax()
uint8_t sedn()
bool seimin()
int8_t sgt()
bool sfilt()

DRV_STATUS

Method Description
uint32_t DRV_STATUS()
uint16_t sg_result()
bool fsactive()
uint8_t cs_actual()
bool stallguard()
bool ot()
bool otpw()
bool s2ga()
bool s2gb()
bool ola()
bool olb()
bool stst()

PWMCONF

Method Description
void PWMCONF(uint32_t)
uint32_t PWMCONF()
void pwm_ampl(uint8_t)
void pwm_grad(uint8_t)
void pwm_freq(uint8_t)
void pwm_autoscale(bool)
void pwm_symmetric(bool)
void freewheel(uint8_t)
uint8_t pwm_ampl()
uint8_t pwm_grad()
uint8_t pwm_freq()
bool pwm_autoscale()
bool pwm_symmetric()
uint8_t freewheel()

PWM_SCALE

Method Description
uint8_t PWM_SCALE()

ENCM_CTRL

Method Description
uint8_t ENCM_CTRL()
void ENCM_CTRL(uint8_t)
void inv(bool)
void maxspeed(bool)
bool inv()
bool maxspeed()

LOST_STEPS

Method Description
uint32_t LOST_STEPS()

Public variables

Method Description
uint8_t status_response