2

I'm trying to communicate with TMC2209 (stepper drive) with an Arduino nano Every. I connected pin RX on pin D2 and TX on pin D3. I placed a 1K resistor between TX and RX. It seems I can write parameters (even I'm testing this deeply, I'm not so sure now..) but I'm not able to read nothing from driver.

Picture added 15/04/2021 related to datasheet of TMC2209 enter image description here

In my test, I tried with only one driver with address 0, means MS1_AD0 and MS2_AD1 connected to GND.

        driver1.microsteps(MICROSTEPS);
        SerialPort.print("Counter1=");
        SerialPort.print(driver1.IFCNT());
        SerialPort.print(", Status=");
        SerialPort.println(driver1.DRV_STATUS());            

I tried reading IFCNT and DRV_STATUS, always ZERO.

The initialization is done in this way:

#include <Wire.h>
#include <AG_AS5600.h>
#include <TMCStepper.h>
#include <AccelStepper.h>

#define ENCODER           false
#define FEEDBACK_I2C      true
#define GEARBOX           139 //51
#define MICROSTEPS        16
#define MIN_SPEED         20
#define MAX_SPEED         3000
double offsetHome       = 77.0;

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
  #define SerialPort SerialUSB
  #define SYS_VOL   3.3
#else
  #define SerialPort Serial
  #define SYS_VOL   5
#endif

#define SW_RX             2       // TMC2208/TMC2224 SoftwareSerial receive pin
#define SW_TX             3       // TMC2208/TMC2224 SoftwareSerial transmit pin
#define EN_PIN            7       // Enable
#define DIR_PIN           8       // Direction
#define STEP_PIN          9       // Step
#define SERIAL_PORT       Serial1 // TMC2208/TMC2224 HardwareSerial port
#define DRIVER_ADDRESS1   0b00    // TMC2209 Driver address according to MS1 and MS2

#define R_SENSE           0.11f   // Match to your driver
                                  // SilentStepStick series use 0.11
                                  // UltiMachine Einsy and Archim2 boards use 0.2
                                  // Panucatt BSD2660 uses 0.1
                                  // Watterott TMC5160 uses 0.075

AG_AMS_5600 ams5600;

TMC2209Stepper driver1(SW_RX, SW_TX, R_SENSE, DRIVER_ADDRESS1);
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);

String cmd            = {};
    
void setup()
{
  SerialPort.begin(115200);
  Wire.begin();
  Wire.setTimeout(10);
  SerialPort.println(">>>>>>>>>> Program started <<<<<<<<<<");
        
  pinMode(EN_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, HIGH);     // Enable driver in hardware

                                  // Enable one according to your setup
  SPI.begin();                    // SPI drivers
  driver1.beginSerial(115200);     // SW UART drivers

  driver1.begin();                 //  SPI: Init CS pins and possible SW SPI pins
                                  // UART: Init SW UART (if selected) with default 115200 baudrate
  driver1.toff(5);                 // Enables driver in software
  driver1.rms_current(2000);       // Set stepper current to 600mA. The command is the same as command TMC2130.setCurrent(600, 0.11, 0.5);
  driver1.microsteps(MICROSTEPS);
  driver1.pwm_autoscale(true);     // Needed for stealthChop 
    
  stepper.setMaxSpeed(degToSteps(500.0));   // steps/s
  stepper.setAcceleration(degToSteps(1.0)); // steps/s^2
  stepper.setEnablePin(EN_PIN);
  stepper.setPinsInverted(false, false, true);
  stepper.disableOutputs();
}


void loop()
{
    unsigned long t0 = micros();  
            
    switch (step) {
      
      case 0:
        cmd = SerialPort.readString();
        
        if (cmd.charAt(0)=='a' && cmd.charAt(1)=='=') {
            acc = degToSteps(cmd.substring(2).toDouble());
            SerialPort.print("Acceleration=");
            SerialPort.println(acc);
            cmd = "";
          }
        else if (cmd.charAt(0)=='d' && cmd.charAt(1)=='=') {
            dec = cmd.substring(2).toInt();
            SerialPort.print("Deceleration=");
            SerialPort.println(dec);            
            cmd = "";
          }
        else if (cmd.charAt(0)=='c' && cmd.charAt(1)=='?') {
            driver1.microsteps(MICROSTEPS);
            driver2.microsteps(MICROSTEPS);
            SerialPort.print("Counter1=");
            SerialPort.print(driver1.IFCNT());
            SerialPort.print(", Counter2=");
            SerialPort.print(driver2.IFCNT());            
            SerialPort.print(", Status=");
            SerialPort.println(driver1.DRV_STATUS());            
            cmd = "";
          }
}

The hardware should be ok because the jumper for UART is configured as default on pin4.

Can someone help me to understand why?

Thanks Andrea

3
  • 1
    I connected pin RX on pin D2 and TX on pin D3. I placed a 1K resistor between TX and RX.. Is there a reason in particular to do that? You should also make sure you connect GND on both boards together if they do no share it already through their power supplies.
    – Marcos G.
    Apr 15, 2021 at 8:48
  • 1
    Thanks for reply, yes, there is a reason, I added the picture above from the datasheet, and yes, GND and also 5Vdc are provided by Arduino. Apr 15, 2021 at 15:35
  • 1
    I see. In my opinion you should start by debugging your hardware. Have you seen this?
    – Marcos G.
    Apr 15, 2021 at 16:49

1 Answer 1

1

I found! The issue was the handling of "software" serial port. Unfortunately I was confused because many examples of "TMCstepper.h" library are shown using two pins as TX and RX, so I was convinced internally pins were handled to send and receive.. but it's not.

So solution I found is:

#include <SoftwareSerial.h>
SoftwareSerial            SerialDriver1(SW_RX, SW_TX);
TMC2209Stepper driver1(&SerialDriver1, R_SENSE, DRIVER_ADDRESS1);

void setup()
{
  SerialDriver1.begin(57600);
  SerialDriver1.listen();
...

and was really important to comment:

 //driver1.beginSerial(115200);     // SW UART drivers

this is important I guess because the port was already opened in the setup by me. and it's necessary to specify the software port where to listen, not done by TMC library.

Last hint, with Arduino Nano Every I found out that Software Serial seems to work with max baudrate of 57600, 115200 was not working.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.