translate from: https://sergey1560-github-io.translate.goog/fb4s_howto/tmc_uart/?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=nl&_x_tr_pto=wapp
Datasheet for driver chip:
TMC 2209 TMC 2208 Description of driver modules from BIGTREETECH:
Manual Video about the operation of stepper motors:
How a stepper motor works Description of stepper motor control:
Stepper motor phase control There are two important driver settings: step division and motor current.
Division of steps This parameter sets how many “steps” the stepper motor will take per pulse on the STEP line. These settings are set either programmatically if the UART interface is connected, or manually by setting jumpers MS1 and MS2. In the case of a manual installation, the steps are given as follows:
#Choice of division of steps
On the robin nano board, these jumpers are under the driver. In this case, we can assume that GND in the table is the removed jumper, and VCC_IO is the installed one.
The default value is 16 microsteps. Those. in order to make 1 full step of the stepper motor, you need to send 16 pulses on the STEP line. Or, in other words, if you send 1 pulse on the STEP line, the stepper motor will turn 1/16 of a step. Given the number of motor steps per revolution and the gear ratio of the drive, for FB4S, for example, it turns out that when dividing the step by 1/16, it takes 80 pulses to move along the X axis by 1 mm. Or, in other words, for 1 pulse, the movement along the X axis will be 0.0125mm.
If you increase the value of the step divider, for example, to 64, then to move 1 mm along the X axis, you will need 320 pulses along the STEP line. Thus, for one pulse, the movement along the X axis will be 0.003125 mm.
#Motor current In manual mode, the maximum current that the driver will supply to the stepper motor is set by rotating the variable resistor on the driver. The voltage at the Vref pin is monitored. Formula for calculation:
Motor current calculation
It should be noted that in the formula the current value is RMS.
In practice, the recommended value of Vref=1.2V corresponds to a current of 900mA (for drivers from BIGTREETECH).
You can configure the driver's operating mode not only with jumpers MS1 and MS2 and a variable resistor, but also programmatically. The driver uses a single-wire UART bus. Moreover, up to 4 drivers can be connected to one bus at the same time. Scheme from the datasheet for the driver:
The diagram shows two connection options: full (read / write) on the left and write-only mode on the right (write only).
In order to access a specific driver on the same line, it is possible to set an address for the driver.
The address is set by jumpers MS1 and MS2. Two bits can set 4 different combinations, which corresponds to the maximum number of drivers on one line.
When controlling the driver via UART, it is possible to set the motor current and set the step divider. The step divider, when set by software, has the following possible values: 1/1, 1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256 (bits 24 -27 register 0x6C).
On the robin nano board, the tracks for connecting drivers via UART are not routed, so you can only connect drivers with wires. On drivers from BIGTREETECH, UART legs are made elongated, so you can connect to them using ordinary dupont wires. The position of the UART leg on the driver depends on the soldered PDN jumper and by default is on the 4th leg of the driver. Read more in the driver manual
On the driver board, you can use the free legs to control the second extruder. In front of the driver connector is a standard pin connector with En, Step, Dir lines.
Step and Dir legs are used to connect drivers. I tried to connect to one leg, without a resistor to the TX line and it still worked. In the final version, I made the circuit as recommended by the driver manufacturer - directly to RX and through a resistor to TX. Connection wire (on the white wire inside the heat shrink 1K resistor):
Connection cable
Robin nano board
In both cases, when connected only to the STEP leg and when connected to STEP and DIR, the drivers work in read-write mode, each driver is controlled individually.
To switch drivers to UART mode, you need to remove the MS3 jumper. This is a pretty important point. The drivers are powered from 5V, so when the MS3 jumper is installed, the UART leg of the driver is closed to the 5V line. If you connect the leg of the UART driver to the STEP line and do not remove the jumper, 5V will fall on the STEP line, which can damage the MCU.
Driver addresses are set by jumpers MS1 and MS2. In this case, the numbering is as follows: X - 0, Y - 1, Z - 2, E - 3.
Marlin has full support for the TMC 2209 drivers, including address setting.
Setting the driver type (Marlin/Configuration.h):
#define X_DRIVER_TYPE TMC2209
#define Y_DRIVER_TYPE TMC2209
#define Z_DRIVER_TYPE TMC2209
#define E0_DRIVER_TYPE TMC2209
To work via UART, you need to set the legs in Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h:
#if HAS_TMC220x
/**
* TMC2208/TMC2209 stepper drivers
*/
//
// Software serial
//
#define X_SERIAL_TX_PIN PA6
#define X_SERIAL_RX_PIN PA1
#define Y_SERIAL_TX_PIN PA6
#define Y_SERIAL_RX_PIN PA1
#define Z_SERIAL_TX_PIN PA6
#define Z_SERIAL_RX_PIN PA1
#define E0_SERIAL_TX_PIN PA6
#define E0_SERIAL_RX_PIN PA1
// Reduce baud rate to improve software serial reliability
#define TMC_BAUD_RATE 19200
#endif
In this case, two legs are used, as recommended in the datasheet. If only one leg is used, the RX and TX pins must be the same.
Driver address settings (Marlin/Configuration_adv.h):
/**
* Four TMC2209 drivers can use the same HW/SW serial port with hardware configured addresses.
* Set the address using jumpers on pins MS1 and MS2.
* Address | MS1 | MS2
* 0 | LOW | LOW
* 1 | HIGH | LOW
* 2 | LOW | HIGH
* 3 | HIGH | HIGH
*
* Set *_SERIAL_TX_PIN and *_SERIAL_RX_PIN to match for all drivers
* on the same serial port, either here or in your board's pins file.
*/
#define X_SLAVE_ADDRESS 0
#define Y_SLAVE_ADDRESS 1
#define Z_SLAVE_ADDRESS 2
#define E0_SLAVE_ADDRESS 3
Setting current and step divider (Marlin/Configuration_adv.h):
#if AXIS_IS_TMC(X)
#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.
#define X_CURRENT_HOME X_CURRENT // (mA) RMS current for sensorless homing
#define X_MICROSTEPS 32 // 0..256
#define X_RSENSE 0.11
#define X_CHAIN_POS -1 // <=0 : Not chained. 1 : MCU MOSI connected. 2 : Next in chain, ...
#endif
#if AXIS_IS_TMC(Z)
#define Z_CURRENT 800
#define Z_CURRENT_HOME Z_CURRENT
#define Z_MICROSTEPS 32
#define Z_RSENSE 0.11
#define Z_CHAIN_POS -1
#endif
#if AXIS_IS_TMC(E0)
#define E0_CURRENT 800
#define E0_MICROSTEPS 32
#define E0_RSENSE 0.11
#define E0_CHAIN_POS -1
#endif
In this case, for all drivers, the current is set to 800mA and the division is 1/32.
Setting steps for 1/32 divider (Marlin/Configuration.h)
/**
* Default Axis Steps Per Unit (steps/mm)
* Override with M92
* X, Y, Z, E0 [, E1[, E2...]]
*/
#define DEFAULT_AXIS_STEPS_PER_UNIT { 160, 160, 800, 800 }
Driver mode (Marlin/Configuration_adv.h):
/**
* TMC2130, TMC2160, TMC2208, TMC2209, TMC5130 and TMC5160 only
* Use Trinamic's ultra quiet stepping mode.
* When disabled, Marlin will use spreadCycle stepping mode.
*/
#define STEALTHCHOP_XY
#define STEALTHCHOP_Z
#define STEALTHCHOP_E
To control drivers, you need to enable (Marlin/Configuration_adv.h):
/**
* Monitor Trinamic drivers
* for error conditions like overtemperature and short to ground.
* To manage over-temp Marlin can decrease the driver current until the error condition clears.
* Other detected conditions can be used to stop the current print.
* Relevant G-codes:
* M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given.
* M911 - Report stepper driver overtemperature pre-warn condition.
* M912 - Clear stepper driver overtemperature pre-warn condition flag.
* M122 - Report driver parameters (Requires TMC_DEBUG)
*/
#define MONITOR_DRIVER_STATUS
#define TMC_DEBUG
This completes the tincture. After flashing, it is important to do Initialize eeprom first.
You can view the status of the drivers with the M122 S0 command . If the value of Driver registers in the output of the command is not 00:00:00:00 or FF:FF:FF:FF, then the connection with the driver is established.
The TMC2208 driver does not have the ability to set an address. Therefore, to connect these drivers, it will not be possible to use only 1 leg. They can be connected using at least 4 legs. If no additional equipment is connected to the board, then the 3 free legs of the second extruder (En, Step, Dir) and the PB2 leg can be used.