# Sensorless Homing with the TMC 2240 drivers

**URL:** <https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438>\
**Category:** General Discussion\
**Created:** [November 7, 2023, 6:58pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438 "2023-11-07T18:58:51Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![hcet14](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hcet14](https://klipper.discourse.group/u/hcet14)\
**Post date:** [November 12, 2023, 2:51pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/21 "2023-11-12T14:51:42Z")

</div>

Ok. What kind of TMC2130 drivers are you using? MKS, BTT, etc…?

---

<div class="post-metadata">

**Author:** ![LifeOfBrian](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/lifeofbrian/32/2380_2.png) [@LifeOfBrian](https://klipper.discourse.group/u/LifeOfBrian)\
**Post date:** [November 12, 2023, 3:22pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/22 "2023-11-12T15:22:19Z")

</div>

How fast are you homing?  
It should not be too slow to generate enough back EMF but also not too fast…

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 12, 2023, 3:25pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/23 "2023-11-12T15:25:39Z")

</div>

> [@hcet14](#):
>
> Ok. What kind of TMC2130 drivers are you using? MKS, BTT, etc…?

the TMC2130 driver is from BTT, but there is no problem with them, as I have already written several times. TMC 2240 are not functional…

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 12, 2023, 3:27pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/24 "2023-11-12T15:27:20Z")

</div>

> [@LifeOfBrian](#):
>
> How fast are you homing?  
> It should not be too slow to generate enough back EMF but also not too fast…

… as recommended 1/2 [rotation\_distance] so 20mm/s

---

<div class="post-metadata">

**Author:** ![LifeOfBrian](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/lifeofbrian/32/2380_2.png) [@LifeOfBrian](https://klipper.discourse.group/u/LifeOfBrian)\
**Post date:** [November 12, 2023, 4:13pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/25 "2023-11-12T16:13:29Z")

</div>

Very strange!

The datasheet only gives the following:

> **Homing with StallGuard2**  
> The homing of a linear drive requires moving the motor into the direction of a hard stop. As StallGuard2 needs a certain velocity to work (as set by TCOOLTHRS), make sure that the start point is far enough away from the hard stop to provide the distance required for the acceleration phase. After setting up SGT, start a motion into the direction of the hard stop and configure diag0\_stall or diag1\_stall to indicate the stall condition to the external controller using one of the diagnostic outputs. Once a stall is detected, the controller stops the motor. The stop condition also is indicated by the flag STALLGUARD in DRV\_STATUS.

Can you maybe try with 40 mm/s?  
Do you still home with reduced motor current or with run current?

---

<div class="post-metadata">

**Author:** ![hcet14](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hcet14](https://klipper.discourse.group/u/hcet14)\
**Post date:** [November 12, 2023, 4:44pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/26 "2023-11-12T16:44:24Z")

</div>

> [@DrumClock](#):
>
> It seems that the DIAG signal is not generated by the driver.

Maybe.

This is what I found out about MKS TMC2240.

 ![bot_pinning_hcet_diag0](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/f/f3359c0cb85204f5fbc01557fc9f144a74d53ab9.jpeg)

> <https://github.com/bigtreetech/BIGTREETECH-TMC2130-V3.0/blob/master/Hardware/2130V3.0%E5%B0%8F%E5%8D%A1%E7%89%87-(%E6%AD%A3%E5%8F%8D%E9%9D%A2).pdf>

BTT might using DIAG1.

You could try to change your config using DIAG0.

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [November 12, 2023, 4:52pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/27 "2023-11-12T16:52:01Z")

</div>

Do you mean to reference this:

> <https://github.com/bigtreetech/BIGTREETECH-Stepper-Motor-Driver/blob/master/TMC2240/Hardware/BIGTREETECH%20TMC2240%20v1.0%20User%20Manual.pdf>

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/a/afe3432dabbde1bceccd93c3981778f38d9299f4.jpeg)

I’m not sure why you’re linking to a TMC2130 page.

Also, why isn’t there a schematic for this module? That would answer a lot of our questions.

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 12, 2023, 5:01pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/28 "2023-11-12T17:01:49Z")

</div>

Hi

1. I don’t know why @hcet14 keeps referring to TMC 2130

2. the TMC 2240 from makerbase MKS does not work for me

3. tomorrow I will try to set DIAG0 and homing speed

Thanks

-Petr

scheme MKS TMC 2240

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/b/b6d53cbe8f8d3aea56d82c09bdfee0ceb7f8ccdb.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/a/aa98d183c45dbe4f7cb0782d78400b4289352ec3.png)

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 12, 2023, 6:23pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/29 "2023-11-12T18:23:39Z")

</div>

HI , I tried this:

1. in the [stepper\_x] section the following changes:  
a) homing\_speed:20  
b) homing\_speed:40  
c) endstop\_pin: tmc2240\_stepper\_x:virtual\_endstop  
d) enstop\_pin: !PA15

2. in the [tmc2240 stepper\_x] section the following changes:  
a) diag1\_pin: ^!PA15  
b) diag0\_pin: ^!PA15  
c) diag1\_pin: PA15 ( the motor did not even move after G28 X0)  
d) diag0\_pin: PA15 ( the motor did not even move after G28 X0)  
e) driver\_SGT: -60  
f) driver\_SGT: 60  
g) driver\_SGT: 0

All attempts did not result in the carriage stop function at the end stop.  
The carrige hit the end and the engine started skipping.

Probably Klipper will not support sensorless homing for TMC 2240.

Does anyone have any ideas what else I should try?

---

<div class="post-metadata">

**Author:** ![LifeOfBrian](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/lifeofbrian/32/2380_2.png) [@LifeOfBrian](https://klipper.discourse.group/u/LifeOfBrian)\
**Post date:** [November 12, 2023, 9:12pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/30 "2023-11-12T21:12:30Z")

</div>

Are you running on StealthChop or SpreadCycle?  
Each mode uses a different StallGuard version, maybe this can help here testing the other mode.

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [November 12, 2023, 10:11pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/31 "2023-11-12T22:11:30Z")

</div>

Thanx for the schematic.

Looking at it, I don’t see anything surprising but I think you’re hung up on the `diag0`/`diag1` pins issue.

Going by the Klipper documentation for the TMC2240

[https://www.klipper3d.org/Config\_Reference.html?h=tmc#tmc2240](https://www.klipper3d.org/Config_Reference.html?h=tmc#tmc2240)

as well as TMC2240 datasheet

> **[TMC2240\_datasheet\_rev1.pdf](https://www.analog.com/media/en/technical-documentation/data-sheets/TMC2240_datasheet_rev1.pdf)**

the `diag1` pin is used as the UART pin when you are in UART mode and does **NOT** provide any error outputs (like StallGuard output) in this mode. **IF YOU ARE WORKING WITH THE BARE CHIP** , you may `diag1` as an error output when you are communicating with the TMC2240 when you are in SPI mode.

I emphasized “IF YOU ARE WORKING WITH THE BARE CHIP” because, if you look at the schematic you’ve provided, `DIAG1/SW` (the correct label) is combined with the `SPI_CS` line with a current limiting resistor (R2 on your schematic) - the current limiting resistor means that any output from `DIAG1/SW` will not change the `SPI_CS` value.

The net result of this is that you need to forget about `diag1` all together. The Klipper documentation kind of notes that but doesn’t explicitly indicate that you will not be able to access `pin_diag1`.

Could you share your current `printer.cfg` and an image of your board for confirming the jumper positions to make sure they’re right (I asked for this previously and never got it). I want to confirm that there is no confusion as to what you are doing and what I and others are assuming.

From there, I will focus on the X axis and check that:

1. You are communicating with the chip (ie no errors indicating that the driver chip’s registers can’t be accessed).
2. The values for the homing movement speed, driver current, SGT value and whether you are running in StealthChop or SpreadCycle mode.
3. Tune the values so that contact with the X axis stop is recognized.

As you are working with a CoreXY, the Y axis should use the same values as the X axis.

Once that’s done, you owe everybody here a beer.

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 13, 2023, 7:34am UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/32 "2023-11-13T07:34:00Z")

</div>

> [@LifeOfBrian](#):
>
> Are you running on StealthChop or SpreadCycle?  
> Each mode uses a different StallGuard version, maybe this can help here testing the other mode.

I tried both StealthChop and SpreadCycle modes.  
Nothing changes, sensorless homing doesn’t work.

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 13, 2023, 7:38am UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/33 "2023-11-13T07:38:49Z")

</div>

Hi @mykepredko

here is the current setup for the TMC2240

> <https://github.com/DrumClock/CoreliX/blob/main/my_config/driver_TMC_2240.cfg>

I am attaching photos of the pins on the MKS board.

 ![IMG_20231113_081943](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/6/6b55e79454cb71a12816b076a3b50c4befa9ab0a.jpeg)  
 ![IMG_20231113_081954](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/c/c8ec99eb12960ad07f6a3ac940401ceb75ed3dc6.jpeg)  
 ![IMG_20231113_082148](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/a/a3a26b07f6dfd10975e48ea7c60fd67a8fb1fbc5.jpeg)

terminal listing (so SPI works)

```auto

8:37 SG4_IND: 00000002 sg4_ind_0=2
8:37 SG4_RESULT: 00000004 sg4_result=4
8:37 SG4_THRS: 00000200 sg4_angle_offset=1
8:37 PWM_AUTO: 0000001d pwm_ofs_auto=29
8:37 PWM_SCALE: 00000000
8:37 PWMCONF: c40c001d pwm_ofs=29 pwm_autoscale=1 pwm_autograd=1 pwm_reg=4 pwm_lim=12
8:37 DRV_STATUS: 80000261 sg_result=609 stst=1
8:37 COOLCONF: 00050000 sgt=5
8:37 CHOPCONF: 34410153 toff=3 hstrt=5 hend=2 tbl=2 tpfd=4 mres=4(16usteps) intpol=1 dedge=1
8:37 MSCURACT: 00930139 cur_a=-199 cur_b=147
8:37 MSCNT: 00000368 mscnt=872
8:37 ADC_TEMP: 000008cc adc_temp=0x08cc(27.8C)
8:37 ADC_VSUPPLY_AIN: 02db099f adc_vsupply=2463 adc_ain=731
8:37 THIGH: 00000000
8:37 TCOOLTHRS: 000fffff tcoolthrs=1048575
8:37 TPWMTHRS: 000fffff tpwmthrs=1048575
8:37 TSTEP: 000fffff tstep=1048575
8:37 TPOWERDOWN: 0000000a tpowerdown=10
8:37 IHOLD_IRUN: 04061f1f ihold=31 irun=31 iholddelay=6 irundelay=4
8:37 GLOBALSCALER: 000000a3 globalscaler=163
8:37 DRV_CONF: 00000001 current_range=1
8:37 IOIN: 4001303c encb=1 enca=1 drv_enn=1 encn=1 output=1 ext_res_det=1 silicon_rv=1 version=0x40
8:37 GSTAT: 00000000
8:37 GCONF: 0000000c en_pwm_mode=1 multistep_filt=1
8:37 ========== Queried registers ==========
8:37 MSLUTSTART: 00f70000 start_sin90=247
8:37 MSLUTSEL: ffff8056 w0=2 w1=1 w2=1 w3=1 x1=128 x2=255 x3=255
8:37 MSLUT7: 00404222 mslut7=4211234
8:37 MSLUT6: 49295556 mslut6=1227445590
8:37 MSLUT5: b5bb777d mslut5=3048961917
8:37 MSLUT4: fbffffff mslut4=4227858431
8:37 MSLUT3: 10104222 mslut3=269500962
8:37 MSLUT2: 24492929 mslut2=608774441
8:37 MSLUT1: 4a9554aa mslut1=1251300522
8:37 MSLUT0: aaaab554 mslut0=2863314260
8:37 ========== Write-only registers ==========
8:37 DUMP_TMC STEPPER=stepper_x

```

and SET\_TMC\_CURRENT

```auto
8:42 Run Current: 0.90A Hold Current: 0.90A
8:42 SET_TMC_CURRENT STEPPER=stepper_x CURRENT=0.9
8:42 Run Current: 0.10A Hold Current: 0.10A
8:42 SET_TMC_CURRENT STEPPER=stepper_x CURRENT=0.1

```

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [November 13, 2023, 3:56pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/34 "2023-11-13T15:56:22Z")

</div>

Good stuff. That looks like what I’m asking for - you’re early posts didn’t have a complete SPI set up and it didn’t sound like you were in communications with the driver module.

Now, going to point 2. Could you create a table (I normally use a spreadsheet) listing the parameters you are using, namely:

- Driver current (`run_current` or, to change for a test, `SET_TMC_CURRENT`)
- Homing speed (`homing_speed:`)
- Running mode (StealthChop or SpreadCycle): (`stealthchop_threshold:` \<== Most people set this to 999999 to ensure StealthChop is always active and I recommend that you use this for these tests)
- SGT Value (`driver_SGT:`) I’m not sure how the values are passed to the TMC2240 so I think you’ll have to try values in the range of 127 and 0 as well as -64 to + 63 (which is 127 to 0 in a 7 bit world) with the higher the most significant bit the higher the sensitivity.

I believe that these are the four parameters that are the critical ones for StallGuard/Sensorless homing.

Once you have the table created, try a few different values, post them here and we’ll figure out how to get things running.

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 13, 2023, 5:21pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/35 "2023-11-13T17:21:27Z")

</div>

Hi @mykepredko

thanks a lot, i figured it out.  
It’s very sensitive, so I don’t know how it will behave when something wears out.

 ![image](https://global.discourse-cdn.com/free1/uploads/klipper/original/2X/9/9dbb24d75ff445fdeaf6f71309ab98de2c114d7a.png)

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [November 13, 2023, 5:48pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/36 "2023-11-13T17:48:04Z")

</div>

Congratulations! I’m very happy for you and hopefully the information here will be of use to somebody else.

I’m surprised at the sensitivity value - when I’m working with a TMC2209, the range is generally 3-5 units.

Great job!

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 13, 2023, 5:51pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/37 "2023-11-13T17:51:51Z")

</div>

Yes, me too. If I do an XY movement test at F36000 speed, it must be `stealthchop_threshold:0`  
otherwise the TMC driver error will occur and the movement will stop.

```auto
max_velocity: 600
max_accel: 6000
max_accel_to_decel:6000

```

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [November 13, 2023, 5:58pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/38 "2023-11-13T17:58:59Z")

</div>

“F36000”? Or do you mean F600 (which matches what you have below it)?

F36000 will have your carriage moving at 130 km/h. I wouldn’t be surprised if the TMC chip throws an error at that speed.

---

<div class="post-metadata">

**Author:** ![DrumClock](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/drumclock/32/177_2.png) [@DrumClock](https://klipper.discourse.group/u/DrumClock)\
**Post date:** [November 13, 2023, 6:04pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/39 "2023-11-13T18:04:18Z")

</div>

i mean … 600 mm/s = G1 x… y … F 36000 (mm/min)

---

<div class="post-metadata">

**Author:** ![mykepredko](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mykepredko/32/2085_2.png) [@mykepredko](https://klipper.discourse.group/u/mykepredko)\
**Post date:** [November 13, 2023, 6:09pm UTC](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438/40 "2023-11-13T18:09:54Z")

</div>

That’s still pretty fast - the maximum speed I run at is 1/3 that (200 mm/s) on my CoreXY’s and Voron 2.4.

Maybe this should go into another topic.

[Previous page](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438.md?page=1)

[Next page](https://klipper.discourse.group/t/sensorless-homing-with-the-tmc-2240-drivers/11438.md?page=3)
