setting up tmc2209 drivers in DEV2

So I am getting ready to try DEV2 on my printer and have a question about settings for 2209 drivers. I am only using them for X and Y. In the define line for stepper motors 

STEPPER_TMC2209_HW_UART(name, stepPin, dirPin, enablePin, serial, rsense, microsteps, currentMillis, stealth, hybridSpeed, slaveAddr, stallSensitivity, fclk, minEndstop, maxEndstop)

I am not sure what value to use for serial, it isn't covered in the docs. Is that the pin on the control board used to communicate with the driver. Also for the slaveAddr i assume that I would assign say X with 1 and Y with 2? is that correct? 

If I am correct with both, does that mean that 2209's can be daisy chained together from the same pin? Thanks!
«1

Comments

  • serial is at least for hw serial the serial id of the processor you use. On which pins these are depends on the chip used. See pinout for that board - it hopefully contains serial numbers as well. TX0/RX0 is serial 0, RX3,TX3 is serial 3.

    slaveAddr is something I never used. I think they are 0 and 1, but you need to define driver for it I think. Never used it as I only had one chip for testing. That I just send the info to the driver library used.
  • edited March 2022
    I am using an arduino due with a ramps fd v2. It looks like D14 and D15 are TX3 and RX3, would both have to connect to the driver? And then set serial to 3 I am assuming.

    What do you mean by send the info to the driver library? How do I do that?

    I don't know very much at all about code so I apologize if these are simple questions, thanks for the help.
  • Yes, that would be serial 3 then.
    >What do you mean by send the info to the driver library? How do I do that?
    Our firmware includes a library for controlling the drivers, we did not write it on our own. There is a field for slaveAddr which gets the value. When you see in the TMC2209 datasheet you see that they also have that as address. Not sure, if your stepper board has a pin to select an address. In that case it would always be 0 and you need one serial per driver then. One of the reasons I prefer the SPI version where only a chip select pin is required and any pin would do.
  • So I set up the X and Y drivers for the 2209's and I am getting this error

    Compiling .pio\build\due\src\SdFat\src\FatLib\FatFile.cpp.o
    In file included from src\io/redefine.h:62:0,
                     from src\Configuration.cpp:35:
    src/Configuration_io.h:168:64: error: lvalue required as unary '&' operand
     STEPPER_TMC2209_HW_UART(XMotor, IOX1Step, IOX1Dir, IOX1Enable, 3, 0.11, 256, 900, true, 80, 0, 60, 12500000, endstopNone, endstopNone)
                                                                    ^
    src\io/io_stepper.h:134:32: note: in definition of macro 'STEPPER_TMC2209_HW_UART'
         TMC2209Stepper name##Inst(&serial, rsense, slaveAddr); \
                                                      ^~~~~~
    src/Configuration_io.h:169:64: error: lvalue required as unary '&' operand
     STEPPER_TMC2209_HW_UART(YMotor, IOY1Step, IOY1Dir, IOY1Enable, 3, 0.11, 256, 900, true, 80, 1, 60, 12500000, endstopNone, endstopNone)
                                                                    ^
    src\io/io_stepper.h:134:32: note: in definition of macro 'STEPPER_TMC2209_HW_UART'
         TMC2209Stepper name##Inst(&serial, rsense, slaveAddr); \
                                                      ^~~~~~
    In file included from src/io/redefine.h:62:0,
                     from src\PrinterTypes\Printer.cpp:598:
    src/Configuration_io.h: In static member function 'static void Printer::setup()':
    src/io/io_stepper.h:181:12: error: request for member 'begin' in '3', which is of non-class type 'int'
         serial.begin(115200); \
                ^
    src/Configuration_io.h:168:1: note: in expansion of macro 'STEPPER_TMC2209_HW_UART'
     STEPPER_TMC2209_HW_UART(XMotor, IOX1Step, IOX1Dir, IOX1Enable, 3, 0.11, 256, 900, true, 80, 0, 60, 12500000, endstopNone, endstopNone)
     ^~~~~~~~~~~~~~~~~~~~~~~
    src/io/io_stepper.h:182:12: error: request for member 'setInterruptPriority' in '3', which is of non-class type 'int'
         serial.setInterruptPriority(5); \
                ^
    src/Configuration_io.h:168:1: note: in expansion of macro 'STEPPER_TMC2209_HW_UART'
     STEPPER_TMC2209_HW_UART(XMotor, IOX1Step, IOX1Dir, IOX1Enable, 3, 0.11, 256, 900, true, 80, 0, 60, 12500000, endstopNone, endstopNone)
     ^~~~~~~~~~~~~~~~~~~~~~~
    src/io/io_stepper.h:181:12: error: request for member 'begin' in '3', which is of non-class type 'int'
         serial.begin(115200); \
                ^
    src/Configuration_io.h:169:1: note: in expansion of macro 'STEPPER_TMC2209_HW_UART'
     STEPPER_TMC2209_HW_UART(YMotor, IOY1Step, IOY1Dir, IOY1Enable, 3, 0.11, 256, 900, true, 80, 1, 60, 12500000, endstopNone, endstopNone)
     ^~~~~~~~~~~~~~~~~~~~~~~
    src/io/io_stepper.h:182:12: error: request for member 'setInterruptPriority' in '3', which is of non-class type 'int'
         serial.setInterruptPriority(5); \
                ^
    src/Configuration_io.h:169:1: note: in expansion of macro 'STEPPER_TMC2209_HW_UART'
     STEPPER_TMC2209_HW_UART(YMotor, IOY1Step, IOY1Dir, IOY1Enable, 3, 0.11, 256, 900, true, 80, 1, 60, 12500000, endstopNone, endstopNone)
     ^~~~~~~~~~~~~~~~~~~~~~~
    *** [.pio\build\due\src\PrinterTypes\Printer.cpp.o] Error 1
    *** [.pio\build\due\src\Configuration.cpp.o] Error 1
    =============================================================================================== [FAILED] Took 2.37 seconds ===============================================================================================
    Environment    Status    Duration
    -------------  --------  ------------
    due            FAILED    00:00:02.369
    ========================================================================================= 1 failed, 0 succeeded in 00:00:02.369 ========================================================================================= 
    The terminal process "C:\Users\jdsis\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'due'" terminated with exit code: 1.

    Terminal will be reused by tasks, press any key to close it.


    This is what I have in my code

    // Define all stepper motors used
    STEPPER_TMC2209_HW_UART(XMotor, IOX1Step, IOX1Dir, IOX1Enable, 3, 0.11, 256, 900, true, 80, 0, 60, 12500000, endstopNone, endstopNone)
    STEPPER_TMC2209_HW_UART(YMotor, IOY1Step, IOY1Dir, IOY1Enable, 3, 0.11, 256, 900, true, 80, 1, 60, 12500000, endstopNone, endstopNone)
    STEPPER_SIMPLE(ZMotor, IOZ1Step, IOZ1Dir, IOZ1Enable, endstopNone, endstopNone)
    STEPPER_SIMPLE(E1MotorBase, IOE1Step, IOE1Dir, IOE1Enable, endstopNone, endstopNone)
    STEPPER_OBSERVEABLE(E1Motor, E1MotorBase)
    STEPPER_SIMPLE(E2MotorBase, IOE2Step, IOE2Dir, IOE2Enable, endstopNone, endstopNone)
    STEPPER_OBSERVEABLE(E2Motor, E2MotorBase)
    STEPPER_SIMPLE(AL1Motor, IOAL1Step, IOAL1Dir, IOAL1Enable, endstopNone, endstopNone)
    STEPPER_SIMPLE(AL2Motor, IOAL2Step, IOAL2Dir, IOAL2Enable, endstopNone, endstopNone)

    I believe the error is from putting 3 for serial, is there something else I have to define to make it work? I tried from 0-3 for serial as that's how many tx/rx pins I have on the DUE. I also tried typing serial3 as well as d14 and 14 which is the digital pin number.
  • So I figured out my problem with serial I think. Serial 3 needed a capitol S, after I did that the error went away. the problem I am having now is that when I try to home or move the motors the X and Y motors just kind of click and don't move while the Z motor does nothing. the way I have the serial connections to the motors is 1 wire going from serial 3(D14 on DUE) to both X and Y 2209 PDN, I am using jumpers to set slave address, Z and EX0 are on simple drivers. is that the correct way to wire them? or do I need to connect both tx3 and rx3 (D14 and D15 on DUE) to PDN with a resistor on one of the wires. I see that on some forums but I also see on rep rap forum it can be done with one wire and no resistor.
    this my configuration.h and then configuration_io.h

    // The following variables are required early to decide on the right modules.
    #define NUM_TOOLS 2
    #define NUM_EXTRUDER 2
    #define NUM_SERVOS 1                  // Number of serves available
    #define MOTHERBOARD 404
    #define EEPROM_MODE 3
    #define RFSERIAL Serial
    //#define EXTERNALSERIAL  use Arduino serial library instead of build in. Requires more RAM, has only 63 byte input buffer.
    // Uncomment the following line if you are using Arduino compatible firmware made for Arduino version earlier than 1.0
    // If it is incompatible you will get compiler errors about write functions not being compatible!
    //#define COMPAT_PRE1
    #define BLUETOOTH_SERIAL 101
    #define BLUETOOTH_BAUD 115200
    #define WAITING_IDENTIFIER "wait"
    #define JSON_OUTPUT 1
    #define FEATURE_WATCHDOG 1
    #define FEATURE_RETRACTION 1
    #define NUM_AXES 4 // X,Y,Z and E for extruder A,B,C would be 5,6,7
    // #define STEPPER_FREQUENCY 153000     // Maximum stepper frequency.
    #define STEPPER_FREQUENCY 100000     // Maximum stepper frequency.
    #define PREPARE_FREQUENCY 1000       // Update frequency for new blocks. Must be higher than PREPARE_FREQUENCY.
    #define BLOCK_FREQUENCY 500          // Number of blocks with constant stepper rate per second.
    #define VELOCITY_PROFILE 2           // 0 = linear, 1 = cubic, 2 = quintic velocity shape
    #define Z_SPEED 10                   // Z positioning speed
    #define XY_SPEED 150                 // XY positioning speed for normal operations
    #define E_SPEED 2                    // Extrusion speed
    #define G0_FEEDRATE 0                // Speed for G0 moves. Independent from set F value! Set 0 to use F value.
    #define MAX_ROOM_TEMPERATURE 15      // No heating below this temperature!
    #define TEMPERATURE_CONTROL_RANGE 20 // Start with controlling if temperature is +/- this value to target temperature
    #define HOST_RESCUE 1                // Enable host rescue help system
    //#define DEBUG_RESCUE                 // Uncomment to add power loss entry in debug menu while printing
    #define POWERLOSS_LEVEL 2       // How much time do we have on powerloss, 0 = no move, 1 = short just raise Z, 2 = long full park move
    #define POWERLOSS_UP 5          // How much to move up if mode 1 is active
    #define Z_PROBE_TYPE 1          // 0 = no z probe, 1 = default z probe, 2 = Nozzle as probe
    #define Z_PROBE_BORDER 2        // Safety border to ensure position is allowed
    #define Z_PROBE_TEMPERATURE 170 // Temperature for type 2

    // 0 = Cartesian, 1 = CoreXYZ, 2 = delta, 3 = Dual X-Axis
    #define PRINTER_TYPE 1
    // steps to include as babysteps per 1/BLOCK_FREQUENCY seconds. Must be lower than STEPPER_FREQUENCY/BLOCK_FREQUENCY and be low enough to not lose steps.
    #define BABYSTEPS_PER_BLOCK \
        { 10, 10, 10 }
    // If all axis end stops are hardware based we can skip the time consuming tests each step
    #define NO_SOFTWARE_AXIS_ENDSTOPS
    // Normally only a delta has motor end stops required. Normally you trigger using axis endstops.
    #define NO_MOTOR_ENDSTOPS

    #define FEATURE_CONTROLLER 0
    // Use more memory to speedup display updates
    #define DISPLAY_FULL_BUFFER 1
    // Direction 1 or -1
    // #define ENCODER_DIRECTION -1
    // Encoder speed 0 = fastest, 1 or 2 = slowest - set so 1 click is one menu move
    // Default is 2 if not set by controller. Use only to fix wrong setting
    #define ENCODER_SPEED 1

    // Dynamically increase the speed at which we step through the menus/change values.
    // Set ENCODER_MAX_REPEAT_STEPS to 1 to disable this. EEPROM/Runtime configurable. (Set to 0 to compile out entirely for extra RAM)
    #define ENCODER_MAX_REPEAT_STEPS 5            // Max. extra steps we can gain.
    #define ENCODER_MAX_REPEAT_TIME_MS 40         // Max. time we have before our extra steps reset.
    #define ENCODER_MIN_REPEAT_TIME_MS 15         // At this repeat rate we accumulate to the max step speed.
    #define ENCODER_APPLY_REPEAT_STEPS_IN_MENUS 1 // Set to 0 to only affect changing config values.

    // Default materials in temperature menus. First value is extruder temp, then bed and chamber temperature. 0 = do not show.
    #define DEFAULT_MATERIALS \
        DEFAULT_MATERIAL(Com::tMatPLA, 215, 60, 0) \
        DEFAULT_MATERIAL(Com::tMatPET, 230, 55, 0) \
        DEFAULT_MATERIAL(Com::tMatASA, 260, 105, 0) \
        DEFAULT_MATERIAL(Com::tMatPC, 275, 110, 0) \
        DEFAULT_MATERIAL(Com::tMatABS, 255, 100, 0) \
        DEFAULT_MATERIAL(Com::tMatHIPS, 220, 100, 0) \
        DEFAULT_MATERIAL(Com::tMatPP, 254, 100, 0) \
        DEFAULT_MATERIAL(Com::tMatFLEX, 240, 50, 0)

    /* Ratios for core xyz. First index denotes motor and second axis.
    For each motor you can set the ratio of x,y,z position that adds
    to the position. 0 = no contribution. */
    // X motor = x + y
    #define COREXYZ_X_X 1
    #define COREXYZ_X_Y 1
    #define COREXYZ_X_Z 0
    // Y motor = x - y
    #define COREXYZ_Y_X 1
    #define COREXYZ_Y_Y -1
    #define COREXYZ_Y_Z 0
    // Z motor = z
    #define COREXYZ_Z_X 0
    #define COREXYZ_Z_Y 0
    #define COREXYZ_Z_Z 1

    // Special geometry definition if printer type is delta
    /*  =========== Parameter essential for delta calibration ===================

                C, Y-Axis
                |                        |___| Carriage horizontal offset
                |                        |   \------------------------------------------
                |_________ X-axis        |    \                                        |
               / \                       |     \  DELTA_DIAGONAL (length)    Each move this Rod Height
              /   \                             \                                 is calculated
             /     \                             \    Carriage is at printer center!   |
             A      B                             \_____/--------------------------------
                                                  |--| End effector horizontal offset (recommend set it to 0)
                                             |----| DELTA_HORIZONTAL_RADIUS (Horizontal rod pivot to pivot measure)

        Column angles are measured from X-axis counterclockwise
        "Standard" positions: alpha_A = 210, alpha_B = 330, alpha_C = 90
    */
    #define DELTA_DIAGONAL 350.0f
    #define DELTA_HORIZONTAL_RADIUS 210.0f
    #define DELTA_PRINT_RADIUS 200.0f
    #define DELTA_ANGLE_A 210.0f
    #define DELTA_ANGLE_B 330.0f
    #define DELTA_ANGLE_C 90.0f
    #define DELTA_CORRECTION_A 0.0f
    #define DELTA_CORRECTION_B 0.0f
    #define DELTA_CORRECTION_C 0.0f
    #define DELTA_RADIUS_CORRECTION_A 0.0f
    #define DELTA_RADIUS_CORRECTION_B 0.0f
    #define DELTA_RADIUS_CORRECTION_C 0.0f
    #define DELTA_HOME_OFFSET_A 0.0f
    #define DELTA_HOME_OFFSET_B 0.0f
    #define DELTA_HOME_OFFSET_C 0.0f

    #define DISABLE_X 0
    #define DISABLE_Y 0
    #define DISABLE_Z 0

    #define FEATURE_AXISCOMP 1
    #define AXISCOMP_TANXY 0
    #define AXISCOMP_TANYZ 0
    #define AXISCOMP_TANXZ 0

    // Next 7 lines are required to make the following work, do not change!
    #include "boards/pins.h"
    #undef IO_TARGET
    #define IO_TARGET 4
    #undef CONFIG_EXTERN
    #define CONFIG_EXTERN extern
    #include "drivers/drivers.h"
    #include "io/redefine.h"

    // Define ZProbe by referencing an endstop defined
    CONFIG_VARIABLE_EQ(EndstopDriver, *ZProbe, &endstopZMin)

    /** Axes are homed in order of priority (0..10) if homing direction is not 0. */
    #define X_HOME_PRIORITY 0
    #define Y_HOME_PRIORITY 1
    #define Z_HOME_PRIORITY 2

    // All fans in this list list become controllable with M106/M107
    // by selecteing the fan number with P0..P<NUM_FANS-1>
    #define NUM_FANS 1
    #define FAN_LIST \
        { &Fan1PWM }

    #define NUM_HEATED_BEDS 1
    #define HEATED_BED_LIST \
        { &HeatedBed1 }

    #define NUM_HEATED_CHAMBERS 0
    #define HEATED_CHAMBER_LIST \
        { }

    #define SERVO_LIST \
        { &Servo1 }
    #define TOOLS \
        { &ToolExtruder1, &ToolExtruder2 }

    // Heaters enumerate all heaters, so we can loop over them
    // or call commands on a specific heater number.
    // Suggested order: extruder heaters, heated beds, heated chambers, additional heaters
    #define NUM_HEATERS 3
    #define HEATERS \
        { &HeaterExtruder1, &HeaterExtruder2, &HeatedBed1 }

    // Array to call motor related commands like microstepping/current if supported.
    // Id's start at 0 and depend on position in this array.
    #define NUM_MOTORS 5
    #define MOTORS \
        { &XMotor, &YMotor, &ZMotor }
    #define MOTOR_NAMES \
        { PSTR("X"), PSTR("Y"), PSTR("Z") }

    // Some common settings for Trinamic driver settings
    /**
     Chopper timing is an array with
     {toff, hend, hstrt}
     See TMC datasheets for more details. There are some predefined values to get you started:
     CHOPPER_TIMING_DEFAULT_12V = { 3, -1, 1 }
     CHOPPER_TIMING_DEFAULT_19V = { 4, 1, 1 }
     CHOPPER_TIMING_DEFAULT_24V = { 4, 2, 1 }
     CHOPPER_TIMING_DEFAULT_36V = { 5, 2, 4 }
     CHOPPER_TIMING_PRUSAMK3_24V = { 3, -2, 6 }

    */
    #define TMC_CHOPPER_TIMING CHOPPER_TIMING_DEFAULT_12V
    // true = interpolate to 256 microsteps for smoother motion
    #define TMC_INTERPOLATE true
    // Current used when motor stands still
    #define TMC_HOLD_MULTIPLIER 0.5
    // Reduce current on over temperature warnings by x milli ampere, 0 = disable
    #define TMC_CURRENT_STEP_DOWN 50
    // Define which data should be stored to eeprom
    #define STORE_MOTOR_MICROSTEPPING 1
    #define STORE_MOTOR_CURRENT 1
    #define STORE_MOTOR_HYBRID_TRESHOLD 1
    #define STORE_MOTOR_STEALTH 1
    #define STORE_MOTOR_STALL_SENSITIVITY 1

    #define X_HOME_DIR -1
    #define Y_HOME_DIR 1
    #define Z_HOME_DIR -1
    #define X_MAX_LENGTH 300
    #define Y_MAX_LENGTH 300
    #define Z_MAX_LENGTH 300
    #define X_MIN_POS 0
    #define Y_MIN_POS 0
    #define Z_MIN_POS 0
    #define BED_X_MIN X_MIN_POS
    #define BED_X_MAX (X_MIN_POS + X_MAX_LENGTH)
    #define BED_Y_MIN Y_MIN_POS
    #define BED_Y_MAX (Y_MIN_POS + Y_MAX_LENGTH)

    // Park position used when pausing from firmware side
    #if PRINTER_TYPE == 2
    #define PARK_POSITION_X (0)
    #define PARK_POSITION_Y (70)
    #define PARK_POSITION_X (X_MIN_POS)
    #define PARK_POSITION_Y (Y_MIN_POS + Y_MAX_LENGTH)
    #define PARK_POSITION_Z_RAISE 10

    #define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X 1100
    #define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y 1100
    #define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z 100
    #define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X 1100
    #define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y 1100
    #define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z 100
    #define XAXIS_STEPS_PER_MM 160
    #define YAXIS_STEPS_PER_MM 160
    #define ZAXIS_STEPS_PER_MM 400

    // ################## EDIT THESE SETTINGS MANUALLY ################
    // ################ END MANUAL SETTINGS ##########################

    #undef Y_MIN_PIN
    #define Y_MIN_PIN -1
    #undef X_MAX_PIN
    #define X_MAX_PIN -1
    #undef Y_MAX_PIN
    #define Y_MAX_PIN ORIG_Y_MIN_PIN
    #undef Z_MAX_PIN
    #define Z_MAX_PIN -1

    #define KILL_IF_SENSOR_DEFECT 0
    #define RETRACT_ON_PAUSE 2
    #define PAUSE_START_COMMANDS ""
    #define PAUSE_END_COMMANDS ""

    #define AUTORETRACT_ENABLED 0
    #define RETRACTION_LENGTH 3
    #define RETRACTION_LONG_LENGTH 13
    #define RETRACTION_SPEED 40
    #define RETRACTION_Z_LIFT 0
    #define RETRACTION_UNDO_EXTRA_LENGTH 0
    #define RETRACTION_UNDO_EXTRA_LONG_LENGTH 0
    #define RETRACTION_UNDO_SPEED 25
    #define FILAMENTCHANGE_X_POS 5
    #define FILAMENTCHANGE_Y_POS 5
    #define FILAMENTCHANGE_Z_ADD 2
    #define FILAMENTCHANGE_REHOME 1
    #define FILAMENTCHANGE_SHORTRETRACT 2.5
    #define FILAMENTCHANGE_LONGRETRACT 50
    #define JAM_METHOD 1
    #define JAM_ACTION 1

    #define RETRACT_DURING_HEATUP true
    #define PID_CONTROL_RANGE 20
    #define EXTRUDE_MAXLENGTH 160

    // ############# Heated bed configuration ########################

    #define SKIP_M190_IF_WITHIN 5
    #define MIN_EXTRUDER_TEMP 150
    #define MILLISECONDS_PREHEAT_TIME 30000

    // ################ Endstop configuration #####################

    #define DOOR_PIN -1
    #define DOOR_PULLUP 1
    #define DOOR_INVERTING 1
    #define ENDSTOP_X_BACK_MOVE 3
    #define ENDSTOP_Y_BACK_MOVE 3
    #define ENDSTOP_Z_BACK_MOVE 1
    #define ENDSTOP_X_RETEST_REDUCTION_FACTOR 2
    #define ENDSTOP_Y_RETEST_REDUCTION_FACTOR 2
    #define ENDSTOP_Z_RETEST_REDUCTION_FACTOR 2
    #define ENDSTOP_X_BACK_ON_HOME 0.5
    #define ENDSTOP_Y_BACK_ON_HOME 0.5
    #define ENDSTOP_Z_BACK_ON_HOME 0
    #define ALWAYS_CHECK_ENDSTOPS 1
    #define MOVE_X_WHEN_HOMED 0
    #define MOVE_Y_WHEN_HOMED 0
    #define MOVE_Z_WHEN_HOMED 0

    // ################# XYZ movements ###################

    #define PREVENT_Z_DISABLE_ON_STEPPER_TIMEOUT 1

    // ##########################################################################################
    // ##                           Movement settings                                          ##
    // ##########################################################################################

    #define FEATURE_BABYSTEPPING 1
    #define BABYSTEP_MULTIPLICATOR 64

    // Delta settings
    #define DELTA_HOME_ON_POWER 0

    #define STEPPER_INACTIVE_TIME 360L
    #define MAX_INACTIVE_TIME 1200L
    #define MAX_FEEDRATE_X 250
    #define MAX_FEEDRATE_Y 250
    #define MAX_FEEDRATE_Z 20
    #define HOMING_FEEDRATE_X 80
    #define HOMING_FEEDRATE_Y 80
    #define HOMING_FEEDRATE_Z 10
    // Raise z before homing (1)
    #define ZHOME_PRE_RAISE 1
    // How much mm should z raise before homing
    #define ZHOME_PRE_RAISE_DISTANCE 2
    #define ZHOME_MIN_TEMPERATURE 0
    #define ZHOME_HEAT_ALL 0
    // Height in mm after homing.
    #define ZHOME_HEIGHT 10
    // Home Z at a fixed xy position (1)
    #define FIXED_Z_HOME_POSITION 1
    #define ZHOME_X_POS 140
    #define ZHOME_Y_POS 45
    // Raise extruders before switching tools. Used to prevent touching objects while switching.
    #define RAISE_Z_ON_TOOLCHANGE 2

    #define ENABLE_BACKLASH_COMPENSATION 0
    #define X_BACKLASH 0
    #define Y_BACKLASH 0
    #define Z_BACKLASH 0
    #define MAX_JERK 5
    #define MAX_ZJERK 0.3
    #define PRINTLINE_CACHE_SIZE 32
    #define MOVE_CACHE_LOW 10
    #define EXTRUDER_SWITCH_XY_SPEED 100
    #define FEATURE_DITTO_PRINTING 0

    // ################# Misc. settings ##################

    #define BAUDRATE 115200
    #define ENABLE_POWER_ON_STARTUP 1
    #define POWER_INVERTING 0
    #define KILL_METHOD 1
    #define ACK_WITH_LINENUMBER 1
    #define KEEP_ALIVE_INTERVAL 2000
    #define ECHO_ON_EXECUTE 1
    #undef PS_ON_PIN
    #define PS_ON_PIN -1

    // #################### Z-Probing #####################

    #define Z_PROBE_COATING 0
    #define Z_PROBE_Z_OFFSET_MODE 1
    #define UI_BED_COATING 1
    #define EXTRUDER_IS_Z_PROBE 1
    #define Z_PROBE_DISABLE_HEATERS 1
    #define Z_PROBE_BED_DISTANCE 3
    #define Z_PROBE_X_OFFSET 0
    #define Z_PROBE_Y_OFFSET 0
    #define Z_PROBE_SPEED 2
    #define Z_PROBE_SWITCHING_DISTANCE 1
    // How often should we test a position 1 .. x. Averages result over all tests.
    #define Z_PROBE_REPETITIONS 1
    // 0 = use average, 1 = use middle value after ordering z
    #define Z_PROBE_USE_MEDIAN 1
    // Nozzle distance to bed when z probe triggers
    #define Z_PROBE_HEIGHT -0.15
    // Delay in ms before we go down again. For BLTouch so signal can disable
    #define Z_PROBE_DELAY 0
    #define Z_PROBE_START_SCRIPT ""
    #define Z_PROBE_FINISHED_SCRIPT ""
    #define Z_PROBE_RUN_AFTER_EVERY_PROBE ""
    #define Z_PROBE_REQUIRES_HEATING 1
    #define Z_PROBE_MIN_TEMPERATURE 150
    #define Z_PROBE_PAUSE_HEATERS 0         // Pause all heaters when probing to reduce EMI artifacts
    #define Z_PROBE_PAUSE_BED_REHEAT_TEMP 5 // Stop and reheat the bed if we leave the target temp by this much.

    // How to correct rotated beds
    // 0 = Software side by rotating coordinates
    // 1 = Move bed physically using 2 motors
    #define LEVELING_CORRECTOR 0
    // Bed fixture coordinates for motor leveling
    #define LC_P1_X 55
    #define LC_P1_Y 130
    #define LC_P2_X 137
    #define LC_P2_Y 45
    #define LC_P3_X 137
    #define LC_P3_Y 210
    #define LC_P2_MOTOR AL1Motor
    #define LC_P3_MOTOR AL2Motor
    #define LC_STEPS_PER_MM 3382
    #define LC_Z_SPEED 0.2
    // > 0 will move bed down and wait for removal (heater removed) and will pause another LC_WAIT_BED_REMOVE seconds
    #define LC_WAIT_BED_REMOVE 2
    // Uncomment to limit correction per autoleveling iteration. Value is the max. correction in mm
    // #define LIMIT_MOTORIZED_CORRECTION 0.5

    // Leveling method
    // 0 = none, 3 = 3 points, 1 = grid, 2 = 4 point symmetric
    #define LEVELING_METHOD 2
    #define L_P1_X 60
    #define L_P1_Y 130
    #define L_P2_X 137
    #define L_P2_Y 45
    #define L_P3_X 137
    #define L_P3_Y 210
    #define MAX_GRID_SIZE 5                   // Maximum grid size allocation in memory, imported grid can be smaller
    #define ENABLE_BUMP_CORRECTION 1          // CPU intensive, so only activate if required
    #define BUMP_CORRECTION_START_DEGRADE 0.5 // Until this height we correct 100%
    #define BUMP_CORRECTION_END_HEIGHT 2      // From this height on we do no correction
    #define BUMP_LIMIT_TO 0                   // Maximum allowed correction up/down, <= 0 off.

    #ifndef SDSUPPORT // Some boards have sd support on board. These define the values already in pins.h
    #define SDSUPPORT 1
    #undef SDCARDDETECT
    #define SDCARDDETECT ORIG_SDCARDDETECT
    #define SDCARDDETECTINVERTED 0
    #define SD_EXTENDED_DIR 1 /** Show extended directory including file length. Don't use this with Pronterface! */
    #define SD_RUN_ON_STOP ""
    #define SD_STOP_HEATER_AND_MOTORS_ON_STOP 1
    #define ARC_SUPPORT 0
    #define FEATURE_MEMORY_POSITION 1
    #define FEATURE_CHECKSUM_FORCED 0
    #define UI_PRINTER_NAME "Testsetup"
    #define UI_PRINTER_COMPANY "Repetier"
    #define UI_PAGES_DURATION 4000
    #define UI_SPEEDDEPENDENT_POSITIONING 0
    #define UI_DISABLE_AUTO_PAGESWITCH 1
    #define UI_AUTORETURN_TO_MENU_AFTER 30000
    #define FEATURE_UI_KEYS 0
    #define UI_ENCODER_SPEED 2
    #define UI_REVERSE_ENCODER 0
    #define UI_KEY_BOUNCETIME 10
    #define UI_KEY_FIRST_REPEAT 500
    #define UI_KEY_REDUCE_REPEAT 50
    #define UI_KEY_MIN_REPEAT 50
    #define CASE_LIGHTS_PIN 25
    #define CASE_LIGHT_DEFAULT_ON 1
    #define UI_START_SCREEN_DELAY 2000

    //#define CUSTOM_EVENTS


    CONFIGURATION_IO.H

    /* Define motor pins here. Each motor needs a setp, dir and enable pin. */

    ENDSTOP_NONE(endstopNone)
    // For use when no output is wanted, but possible
    IO_OUTPUT_FAKE(fakeOut)

    // X Motor

    IO_OUTPUT(IOX1Step, ORIG_X_STEP_PIN)
    IO_OUTPUT_INVERTED(IOX1Dir, ORIG_X_DIR_PIN)
    IO_OUTPUT(IOX1Enable, ORIG_X_ENABLE_PIN)

    // Y Motor

    IO_OUTPUT(IOY1Step, ORIG_Y_STEP_PIN)
    IO_OUTPUT(IOY1Dir, ORIG_Y_DIR_PIN)
    IO_OUTPUT(IOY1Enable, ORIG_Y_ENABLE_PIN)

    // Z Motor

    IO_OUTPUT(IOZ1Step, ORIG_Z_STEP_PIN)
    IO_OUTPUT_INVERTED(IOZ1Dir, ORIG_Z_DIR_PIN)
    IO_OUTPUT(IOZ1Enable, ORIG_Z_ENABLE_PIN)

    // E0 Motor

    IO_OUTPUT(IOE1Step, ORIG_E0_STEP_PIN)
    IO_OUTPUT_INVERTED(IOE1Dir, ORIG_E0_DIR_PIN)
    IO_OUTPUT_INVERTED(IOE1Enable, ORIG_E0_ENABLE_PIN)

    // E1 Motor

    IO_OUTPUT(IOE2Step, ORIG_E1_STEP_PIN)
    IO_OUTPUT(IOE2Dir, ORIG_E1_DIR_PIN)
    IO_OUTPUT_INVERTED(IOE2Enable, ORIG_E1_ENABLE_PIN)

    // Autolevel Motor 1

    IO_OUTPUT(IOAL1Step, 51)
    IO_OUTPUT(IOAL1Dir, 53)
    IO_OUTPUT_INVERTED(IOAL1Enable, 49)

    // Autolevel Motor 1

    IO_OUTPUT(IOAL2Step, 39)
    IO_OUTPUT(IOAL2Dir, 13)
    IO_OUTPUT_INVERTED(IOAL2Enable, 40)

    // Servo output

    IO_OUTPUT(Servo1Pin, 5)

    // Define your endstops inputs

    IO_INPUT_PULLUP(IOEndstopXMin, ORIG_X_MIN_PIN)
    IO_INPUT_PULLUP(IOEndstopYMin, ORIG_Y_MIN_PIN)
    // Assume we're using a BLTouch by default.
    //IO_INPUT_PULLUP(IOEndstopZProbe, BLTOUCH_Z_MIN)
    IO_INPUT_PULLUP(IOEndstopZMax, ORIG_Z_MAX_PIN)

    IO_INPUT(IOJam1, 35)
    IO_INPUT(IOJam2, 33)

    // Controller input pins

    #if defined(UI_ENCODER_CLICK) && UI_ENCODER_CLICK >= 0
    IO_INPUT_INVERTED_PULLUP(ControllerClick, UI_ENCODER_CLICK)
    IO_INPUT_DUMMY(ControllerClick, false)
    #if defined(UI_ENCODER_A) && UI_ENCODER_A >= 0
    IO_INPUT_INVERTED_PULLUP(ControllerEncA, UI_ENCODER_A)
    IO_INPUT_DUMMY(ControllerEncA, false)
    #if defined(UI_ENCODER_B) && UI_ENCODER_B >= 0
    IO_INPUT_INVERTED_PULLUP(ControllerEncB, UI_ENCODER_B)
    IO_INPUT_DUMMY(ControllerEncB, false)
    #if defined(UI_BACK_PIN) && UI_BACK_PIN >= 0
    IO_INPUT_PULLUP(ControllerBack, UI_BACK_PIN)
    IO_INPUT_DUMMY(ControllerBack, false)
    #if defined(UI_RESET_PIN) && UI_RESET_PIN >= 0
    IO_INPUT_PULLUP(ControllerReset, UI_RESET_PIN)
    IO_INPUT_DUMMY(ControllerReset, false)

    // Define our endstops solutions
    // You need to define all min and max endstops for all
    // axes except E even if you have none!

    ENDSTOP_SWITCH_HW(endstopXMin, IOEndstopXMin, X_AXIS, false)
    ENDSTOP_SWITCH_HW(endstopYMin, IOEndstopYMin, Y_AXIS, false)
    ENDSTOP_SWITCH_HW(endstopZMax, IOEndstopZMax, Z_AXIS, true)
    ENDSTOP_NONE(endstopZMin)
    //ENDSTOP_SWITCH_HW(endstopZProbe, IOEndstopZProbe, ZPROBE_AXIS, false)

    ENDSTOP_NONE(endstopXMax)
    ENDSTOP_NONE(endstopYMax)

    // Define fans

    IO_OUTPUT(IOFan1, ORIG_FAN_PIN)
    IO_PWM_SOFTWARE(Fan1NoKSPWM, IOFan1, 0)
    // IO_PWM_HARDWARE(Fan1PWM, 37,5000)
    // IO_PDM_SOFTWARE(Fan1NoKSPWM, IOFan1) // alternative to PWM signals
    IO_PWM_KICKSTART(Fan1PWM, Fan1NoKSPWM, 20, 85)
    // For debugging - reports new values and then calls real pwm
    // IO_PWM_REPORT(Fan1Report, Fan1PWM)
    // Define temperature sensors

    // Typically they require an analog input (12 bit) so define
    // them first.

    IO_ANALOG_INPUT(IOAnalogBed1, TEMP_1_PIN, 5)
    IO_ANALOG_INPUT(IOAnalogExt1, TEMP_0_PIN, 5)
    IO_ANALOG_INPUT(IOAnalogExt2, TEMP_2_PIN, 5)

    // Need a conversion table for epcos NTC
    IO_TEMP_TABLE_NTC(TempTableEpcos, Epcos_B57560G0107F000)

    // Now create the temperature inputs

    IO_TEMPERATURE_TABLE(TempBed1, IOAnalogBed1, TempTableEpcos)
    IO_TEMPERATURE_TABLE(TempExt1, IOAnalogExt1, TempTableEpcos)
    IO_TEMPERATURE_TABLE(TempExt2, IOAnalogExt2, TempTableEpcos)

    // Use PWM outputs to heat. If using hardware PWM make sure
    // that the selected pin can be used as hardware pwm otherwise
    // select a software pwm model whcih works on all pins.

    #if MOTHERBOARD == 405
    IO_PWM_HARDWARE(PWMExtruder1, HEATER_0_PIN, 1000)
    IO_PWM_HARDWARE(PWMExtruder2, HEATER_2_PIN, 1000)
    IO_PWM_HARDWARE(PWMBed1, HEATER_1_PIN, 1000)
    IO_OUTPUT(IOExtr1, HEATER_0_PIN)
    IO_OUTPUT(IOExtr2, HEATER_2_PIN)
    IO_OUTPUT(IOBed1, HEATER_1_PIN)
    IO_PWM_SOFTWARE(PWMExtruder1, IOExtr1, 1)
    IO_PWM_SOFTWARE(PWMExtruder2, IOExtr2, 1)
    IO_PWM_SOFTWARE(PWMBed1, IOBed1, 1)
    // IO_OUTPUT(IOCooler1, FAN2_PIN)
    // IO_PWM_SOFTWARE(PWMCoolerExt1, FAN2_PIN, 0)

    // Define all stepper motors used
    STEPPER_TMC2209_HW_UART(XMotor, IOX1Step, IOX1Dir, IOX1Enable, Serial3, 0.11, 32, 900, true, 80, 0, 60, 12500000, endstopNone, endstopNone)
    STEPPER_TMC2209_HW_UART(YMotor, IOY1Step, IOY1Dir, IOY1Enable, Serial3, 0.11, 32, 900, true, 80, 1, 60, 12500000, endstopNone, endstopNone)
    STEPPER_SIMPLE(ZMotor, IOZ1Step, IOZ1Dir, IOZ1Enable, endstopNone, endstopNone)
    STEPPER_SIMPLE(E1MotorBase, IOE1Step, IOE1Dir, IOE1Enable, endstopNone, endstopNone)
    STEPPER_OBSERVEABLE(E1Motor, E1MotorBase)
    STEPPER_SIMPLE(E2MotorBase, IOE2Step, IOE2Dir, IOE2Enable, endstopNone, endstopNone)
    STEPPER_OBSERVEABLE(E2Motor, E2MotorBase)
    STEPPER_SIMPLE(AL1Motor, IOAL1Step, IOAL1Dir, IOAL1Enable, endstopNone, endstopNone)
    STEPPER_SIMPLE(AL2Motor, IOAL2Step, IOAL2Dir, IOAL2Enable, endstopNone, endstopNone)

    // Servos
    SERVO_ANALOG(Servo1, 0, Servo1Pin, 500, 2500, 1050)

    // Heat manages are used for every component that needs to
    // control temperature. Higher level classes take these as input
    // and simple heater like a heated bed use it directly.

    HEAT_MANAGER_PID(HeatedBed1, 'B', 0, TempBed1, PWMBed1, 120, 255, 1000, 5, 30000, 12.0, 33.0, 290.0, 80, 255, true)
    HEAT_MANAGER_PID(HeaterExtruder1, 'E', 0, TempExt1, PWMExtruder1, 260, 255, 1000, 10, 20000, 20.0, 0.6, 65.0, 40, 220, false)
    HEAT_MANAGER_PID(HeaterExtruder2, 'E', 1, TempExt2, PWMExtruder2, 260, 255, 1000, 10, 20000, 20.0, 0.6, 65.0, 40, 220, false)

    // HEAT_MANAGER_DYN_DEAD_TIME(HeaterExtruder1, 'E', 0, TempExt1, PWMExtruder1, 260, 255, 100, 10, 20000, 150, 7, 7, 200, 7, 7, false)
    // HEAT_MANAGER_DYN_DEAD_TIME(HeaterExtruder2, 'E', 1, TempExt2, PWMExtruder2, 260, 255, 100, 10, 20000, 150, 7, 7, 200, 7, 7, false)

    // Coolers are stand alone functions that allow it to control
    // a fan with external sensors. Many extruders require a cooling
    // fan pointer to the extruder to prevent heat rising up.
    // These can be controlled by the cooler. Since it is
    // independent you just tell what part needs cooling.
    // Other use cases are board cooling and heated chambers.

    // Define tools. They get inserted into a tool array in configuration.h
    // Typical tools are:
    // TOOL_EXTRUDER(name, offx, offy, offz, heater, stepper, resolution, yank, maxSpeed, acceleration, advance, startScript, endScript)

    TOOL_EXTRUDER(ToolExtruder1, 0, 0, 0, HeaterExtruder1, /*AL1Motor */ E1Motor, 1.75, 292, 5, 30, 5000, 40, "M117 Extruder 1", "", &Fan1PWM)
    TOOL_EXTRUDER(ToolExtruder2, 16.775, 0.615, -0.97, HeaterExtruder2, /*AL2Motor */ E2Motor, 1.75, 147.0, 5, 30, 5000, 40, "M117 Extruder 2\nM400\nM340 P0 S1500 R600\nG4 P300", "M340 P0 S800 R600\nG4 P300", &Fan1PWM)
    TOOL_LASER(Laser3, 0, 0, 0, Fan1NoKSPWM, fakeOut, fakeOut, 3000, 1, 100, 150.0, 1.5, "", "")
    TOOL_CNC(CNC4, 0, 0, 0, Fan1NoKSPWM, fakeOut, fakeOut, fakeOut, 7000, 3000, "", "")

    // Use a signal that changes while extruder moves
    JAM_DETECTOR_HW(JamExtruder1, E1Motor, IOJam1, ToolExtruder1, 220, 10, 500)
    JAM_DETECTOR_HW(JamExtruder2, E2Motor, IOJam2, ToolExtruder2, 220, 10, 500)

    // Use a signal that is high, when filament is loaded
    //FILAMENT_DETECTOR(FilamentDetector1, IOJam1, ToolExtruder1)
    //FILAMENT_DETECTOR(FilamentDetector2, IOJam2, ToolExtruder2)

  • Have a look at the motion g-codes, especially M122
    https://docfirmwarev2.repetier.com/GCodes/motion_gcodes#m122

    It shows settings read from driver. You should first ensure communication is working and best test is to see your settings. You can test changing microsteps and see if they changed for example.

    Regarding wiring serial - you know that for serial connection TX goes to RX and vice versa? In my test with one driver I did not use a resistor. Assumed stepper board would include that if required.

    For Z motor check if it is blocking at startup and loose after motion. If so your need to invert the enable pin.
  • So what you are saying is I need to connect tx3 from DUE to rx on 2209 and rx3 from DUE to tx on 2209? I think I was getting it wrong because reading about marlin it can handle uart over just one wire. 

    I tried m122 and microsteps do not change so I think my wiring is wrong. I will change my wiring to how I described it above if that is what you mean.

    I inverted enable for z motor and it started working.

    Thank you.
  • >  it wrong because reading about marlin it can handle uart over just one wire. 
    Yes there was something. Been a few years ago I did that. You need to have special wiring with that right? Normal serial is as I wrote and that is what hardware serial uses. 2209 has single wire uart so ther eis no RX/TX at all on that chip - they get converted somehow, but I forget how. But it sounds like you already know how. It's the same library as marlin uses so same wiring I'd say.
  • Well I've got the uart connection working, I can read state with m122 and they change when I change parameters, and i can now control X Y and Z motors. I am having trouble getting sensorless homing to work. 

    This is what I have setup up for endstops. I have tried inverting them with no luck. I've varied sensitivity all over the place. does sensorless homing need to be defined somewhere? Thanks again for all the help!

    IO_INPUT_PULLUP(IOEndstopXMin, ORIG_X_MIN_PIN)
    IO_INPUT_PULLUP(IOEndstopYMin, ORIG_Y_MIN_PIN)
    IO_INPUT_PULLUP(IOEndstopZMax, ORIG_Z_MAX_PIN)

    ENDSTOP_SWITCH_HW(endstopXMin, IOEndstopXMin, X_AXIS, false)
    ENDSTOP_SWITCH_HW(endstopYMin, IOEndstopYMin, Y_AXIS, false)
    ENDSTOP_SWITCH_HW(endstopZMax, IOEndstopZMax, Z_AXIS, true)
    ENDSTOP_NONE(endstopZMin)
    ENDSTOP_NONE(endstopXMax)
    ENDSTOP_NONE(endstopYMax)

    STEPPER_TMC2209_HW_UART(XMotor, IOX1Step, IOX1Dir, IOX1Enable, Serial3, 0.11, 32, 900, true, 80, 0, 60, 12, endstopNone, endstopNone)
    STEPPER_TMC2209_HW_UART(YMotor, IOY1Step, IOY1Dir, IOY1Enable, Serial3, 0.11, 32, 900, true, 80, 1, 60, 12, endstopNone, endstopNone)
    STEPPER_SIMPLE(ZMotor, IOZ1Step, IOZ1Dir, IOZ1Enable, endstopNone, endstopNone)

  • If anyone has a setup working with sensorless homing could you share your configuration and configuration_io files. Thanks in advance.
  • You have defined silent for motors. In silent mode sensorless homing does not work. Also did you add a cable from diag1 to the pin for end stop? Then in addition you need a minimum speed for the sensorless homing to trigger. This depends on motor used and how good it causes back emf on stall.
  • I tried defining false for stealth and had no change. I have wires going from diag1 to the endstop for each driver. How do I set a minimum speed for it to trigger? Is that with this define

      #define TMC2130_TCOOLTHRS_X 1048575

    I saw that in another discussion on here. I would assume if is that I would have to change TMC2130 to TMC2209.
  • TMC2130_TCOOLTHRS_X is not used in our sources, no idea where you got that from. Maybe it was a setting in V1 firmware that only supports that driver.

    There is no setting for minimum speed. Homing speed must just be fast enough to work. 10-20mm/s should do fine.

    There is a parameter stallguard sensitivity that defines the required motor response to trigger.

    I checked the sources in stepper.cpp
    // Called before homing starts. Can be used e.g. to disable silent mode
    // or otherwise prepare for endstop detection.
    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::beforeHoming() {
    }

    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::afterHoming() {
    }

    would be responsible to enable/disable it. As you see in 2209 it is empty.
    While for tmc2130 where I tested it with I have this code

    // Called before homing starts. Can be used e.g. to disable silent mode
    // or otherwise prepare for endstop detection.
    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2130Driver<stepCls, dirCls, enableCls, fclk>::beforeHoming() {
    if (hasStallguard()) {
    driver->TCOOLTHRS(0xFFFFF);
    driver->en_pwm_mode(false);
    driver->diag1_stall(true);
    }
    }

    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2130Driver<stepCls, dirCls, enableCls, fclk>::afterHoming() {
    if (hasStallguard()) {
    driver->TCOOLTHRS(0);
    driver->en_pwm_mode(stealthChop);
    driver->diag1_stall(false);
    }
    }

    I think that is the main reason it does not work. Can you try copying the code from 2130 to 2209 and see if it compiles. Especially the driver->diag1_stall(true); is resposible in 2130 that it gets enabled.

    As you see it is only enabled for homing and nothing else.

  • Sorry changing code will not work. Have checke dit and functions simply do not exists. Would need to read the datasheets etc to figure out how to do that exactly but I have no test hardware to verify anyway and for which I currently have no time. So at the current time it will not work sensorless also I think the chip can do.

    If you have some programming skills you might try to figure it out. It is just these 2 function that need to be modified to enable and disable the mode. The question is which driver functions to call.
  • I can understand not having time, I do appreciate the help you have given me.I have very little experience with code other then very basic. If I am understanding you correctly basically what happens just before homing and just after homing needs to be put in stepper.cpp, Is that right?
  • edited March 2022
    I found this in marlin firmware  tmc_util.cpp It seems like the same sort of set up where it enables and disables stallguard for homing. I included what they are using for tmc2130 to show that it is more or less the same as repetier has in stepper.cpp. To me it looks like the 2209 is staying in stealthchop for homing.

     bool tmc_enable_stallguard(TMC2130Stepper &st) {
        const bool stealthchop_was_enabled = st.en_pwm_mode();

        st.TCOOLTHRS(0xFFFFF);
        st.en_pwm_mode(false);
        st.diag1_stall(true);

        return stealthchop_was_enabled;
      }
      void tmc_disable_stallguard(TMC2130Stepper &st, const bool restore_stealth) {
        st.TCOOLTHRS(0);
        st.en_pwm_mode(restore_stealth);
        st.diag1_stall(false);
      }

      bool tmc_enable_stallguard(TMC2209Stepper &st) {
        const bool stealthchop_was_enabled = !st.en_spreadCycle();

        st.TCOOLTHRS(0xFFFFF);
        st.en_spreadCycle(false);
        return stealthchop_was_enabled;
      }
      void tmc_disable_stallguard(TMC2209Stepper &st, const bool restore_stealth) {
        st.en_spreadCycle(!restore_stealth);
        st.TCOOLTHRS(0);



    I tried putting this into stepper.cpp to the best of my ability. I keep getting an error on compiling in HAL.h that says '__disable_irq' was not declared in this scope.  I'm not sure what this means. Here is how I wrote it out

    // Called before homing starts. Can be used e.g. to disable silent mode
    // or otherwise prepare for endstop detection.
    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::beforeHoming() {
        if (hasStallguard()) {
            driver->TCOOLTHRS(0xfffff);
            driver->en_spreadCycle(false);
            return stealthchop_was_enabled;
        }
    }

    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::afterHoming() {
        if (hasStallguard()) {
            driver->en_spreadcycle(!restore_stealth);
            driver->TCOOLTHRS(0);
        }
    }
  • Great, marlin sources help here. Adjusted corrected stepper.cpp part would look like this then:

    // Called before homing starts. Can be used e.g. to disable silent mode
    // or otherwise prepare for endstop detection.
    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::beforeHoming() {
    if (hasStallguard()) {
    driver->TCOOLTHRS(0xFFFFF);
    driver->en_spreadCycle(false);
    }
    }

    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::afterHoming() {
    if (hasStallguard()) {
    driver->en_spreadcycle(stealthChop);
    driver->TCOOLTHRS(0);
    }
    }


    You used restore_stealth which does not exists. I wonder why they do not need to enable diag1 here to report it, but maybe it does always anyway. Would explain why that function does not exist and why also marlin only calls it for tmc2130 and not 2209.

    __disable_irq is normally regular part of it. Please copy full error report for that error if it still exists with my code version. That function is used for due at many places so normally works and is present.
  • edited March 2022
    It works!!! I can confirm that the code you gave me enables sensorless homing with tmc2209 drivers, and its working with them on both X and Y. I don't know if you want to put this in the code without testing yourself but it is working for me. Thanks so much for the help!  For anyone who my be reading this in the future when you are defining tmc2209 in configuration_io.h, for serial you need to write SerialX( X being which serial port on your board you are using for UART). Slave address does work so you can control up to 4 drivers from one serial port. To do this make a "Y" wire that connects both TX and RX lines together, put a 1k ohm resistor on the TX wire before the "Y", after the "Y" connect it to the PDN pin on each TMC2209 driver board. The slave address is from 0-3, to configure each drivers slave address use ms1 and ms2 on the control board. Nothing on either is slave 0, ms1 jumper on is slave 1, ms2 jumper is slave 2, both ms1 and ms2 jumper is slave 3. If its not put in the code you will have to put this in stepper.cpp. It is near the bottom, just search TMCStepper2209 and look for the part that matches this. The driver-> parts will be missing, put the values below in and it will work. 

     // Called before homing starts. Can be used e.g. to disable silent mode
    // or otherwise prepare for endstop detection.
    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::beforeHoming() {
    if (hasStallguard()) {
    driver->TCOOLTHRS(0xFFFFF);
    driver->en_spreadCycle(false);
    }
    }

    template <class stepCls, class dirCls, class enableCls, uint32_t fclk>
    void TMCStepper2209Driver<stepCls, dirCls, enableCls, fclk>::afterHoming() {
    if (hasStallguard()) {
    driver->en_spreadcycle(stealthChop);
    driver->TCOOLTHRS(0);
    }
    }
  • Thanks for confirming. I have published the modifications, so they are now official part of V2.
  • Awesome, thanks again for taking the time to help. If you would like, when I get my printer config complete and tested I would be willing to send you the configuration.h and configuration_io.h files to use as a sample system for a corexy with DUE and ramps fdv2. Let me know.
  • Sounds good to have some more samples, also keeping them up to date with changes is an other thing. But better then nothing in any case and I have a sample with sensorless homing and TMC2209.
  • So one more question. Is there a way to add a delay between each axis homing? I am finding that with the way sensorless homing works there needs to be a delay between when x finishes homing and y starts to home to give the drivers a second to stop sending a homing signal. This is probably only for a corexy because both motors stall at the same time when homing one axis. Probably only needs to be 1 sec delay between x and y homing.
  • Good point. You must at least go back after last trigger so it is never triggered - a mm or 2 should suffice. The back move has test disabled I think, but when switching to y the x motor must have untriggered as you describe.

    Since I don't have a system with sensorless homing I never had the problem so not implemented, but easy to add.
    In file MotionLevel1.cpp the function
    bool Motion1::simpleHome(fast8_t axis) {

    is responsible for homing a single axis.

    A delay of 300ms can be added by
    HAL::delayMilliseconds(300);

    Now question is where. There is a mode called safe homing which also requires that sensors untrigger after moving back. Here you would also get same problem. So I think the delay should correctly be added after every back move in that function.

    So for first test you should add it here
    // Move back for retest
    if (ok) {
    endstopMode = EndstopMode::DISABLED;
    eStop.resetHistory();
    dest[axis] = -homeDir[axis] * homeRetestDistance[axis];
    Motion1::axesTriggered = 0;
    moveRelativeByOfficial(dest, homingFeedrate[axis], false);
    waitForEndOfMoves();
    HAL::delayMilliseconds(300); // <---------------------------------------
    // retest

    The second one is

    endstopMode = EndstopMode::DISABLED;
    setHardwareEndstopsAttached(false, &eStop);
    if (ok) {
    moveRelativeByOfficial(dest, homingFeedrate[axis], false); // also adds toolOffset!
    waitForEndOfMoves();
    HAL::delayMilliseconds(300); // <---------------------------------------
    #ifdef DEBUG_MOVES
    reportPosition(PSTR("simpleHome C"), true);
    }


    Adding simple delay is not best solution, but good for a test now. Please report if it helps and I add a perfect solution to pull. But as long as delay does not get too high it is no real problem. Only temperature management does not work during delay so delays up to 1s should be no problem at all. The improved solution will then get a config option and delay with update.
  • The second is the one that adds a delay between each axis homing so that works but I can't get the x axis to back off when it finishes homing before y starts to home. I think that is keeping the motor in a stall state and triggering the y endstop immediately.
  • The backof distance is defined in configuration.h
    #define ENDSTOP_X_BACK_ON_HOME 0.5
    but may also come from older upload in eeprom, so check that as well or reset to config value
    M502
    M500

    For moving the release move end stop test gets disabled in simpleHome:
    endstopMode = EndstopMode::DISABLED;
    setHardwareEndstopsAttached(false, &eStop);
    if (ok) {
    moveRelativeByOfficial(dest, homingFeedrate[axis], false); // also adds toolOffset!
    waitForEndOfMoves();


    So I hope reason is that the back distance was just too low.
  • Wow I feel dumb, I was changing back on home in vscode not realizing it wasn't updating in the eeprom. so that was an easy fix. The delay in the second example seems to help somewhat but its spotty. I tried up to a 2500ms delay and it was hit or miss if the stall would untrigger. I have been looking around the internet and it seems like marlin and klipper are disabling the second check of each endstop. From what they say with the sensorless homing you cant get any more accurate than the first test because it stalls to the closest full step of the motor. So is there a way to eliminate the second check of each endstop? 
  • Disabling second check is not possible in current version. For next update I have added a mod in simpleHome

    // Move back for retest
    if (ok) {

    into

    // Move back for retest
    if (ok && homeRetestDistance[axis] > 0) {

    Then setting rehome distance to 0 disables second check. But I do not think that solves the issue. The back move does not test end stop but when switching to y and the diag pin is still triggered it will stop y move directly. Guess that is what you see?

    You might try sending
    M111 S70
    before homing. This enables end stop debugging so you get a list of state changes when pin changes. Should help to see if and when the sensor gets untriggered. Saw also some threads where it was a problem that the sensor did not untrigger.

    In datasheet I read for diag pin

    DIAG 11 DO Diagnostic and StallGuard output. Hi level upon stall detection or driver error. Reset error condition by ENN=high.

    ENN is motor enabled signal. So as a test with above single test homing run
    G28 X0
    M84
    G28 Y0
    M84

    And see if that works. With end stop debugging the signal should change the moment power gets disabled. A bit awkward to reset signal by disabling motor as that might move motor as well.
  • "Then setting rehome distance to 0 disables second check. But I do not think that solves the issue. The back move does not test end stop but when switching to y and the diag pin is still triggered it will stop y move directly. Guess that is what you see?"

    Yes. When testing g28, I have a meter connected to endstop and it seems that the diag pin goes low between the first and second check but stays high after the second check which stops the y move directly. 

    I will try m111 s70 when I get home to see if that is truly the case. I will also try
    G28 X0
    M84
    G28 Y0
    M84
  • > and it seems that the diag pin goes low between the first and second check but stays high after the second
    That would contradict that it stays high until enable gets disabled. But if that is the case it would be good and moving back same distance the second time should then also disable it. It might require a number of steps to disable the signal, so something to test as well.
  • Trying g28 x0 m84 g28 y0 m84 didn't seem to stop the issue. The homing would still stop sometimes when Y started to home.

    I think I figured it out. The RETEST_REDUCTION_FACTOR needs to be set to 1 for both X and Y to keep the same speed for the second test. it seems that stallguard sensitivity is pretty finicky with the set speed for homing. When the homing speed changed on the second test it would technically need a different stall value. Setting that correctly and setting BACK_ON_HOME to at least 10 have given me perfect homing every time I have tried so far. I am not sure why the reduction factor was affecting when X stops and Y starts but it has made the issue go away, at least in the testing I have done so far. 


Sign In or Register to comment.