UART not communicating

For whatever reason I cannot seem to get UART to set the proper steps or current to my driver with this code. I tried to copy from the examples as best as I could but I am still seemingly not able to get any communication with the driver. Im using pin 7 and 8 for UART communication with a Fysect 2209 V4.0 Driver.

#include <SoftwareSerial.h>
#include <TMCStepper.h>
#include <AccelStepper.h>

//Define Pins
//For LP:
#define UpPin A0
#define DownPin A1
//For DAC:
//#define UpPin A2
//#define DownPin A3
///===
#define EnInput 4
#define EnOutput 5
#define DirPin 2
#define StepPin 3

//Software Serial Setup Pin
#define SW_TX 7
#define SW_RX 8
#define DRIVER_ADDRESS 0b00
#define R_SENSE 0.11f

//TMCStepper Setup
SoftwareSerial SoftSerial(SW_RX, SW_TX);                          // Be sure to connect RX to TX and TX to RX between both devices
TMC2209Stepper TMCdriver(&SoftSerial, R_SENSE, DRIVER_ADDRESS);   // Create TMC driver

//Accel Stepper Setup
AccelStepper Stepper(AccelStepper::DRIVER, StepPin, DirPin);

void setup() {
  Serial.begin(11520);
  SoftSerial.begin(11520);
  TMCdriver.beginSerial(11520);
  pinMode(EnInput, INPUT);
  pinMode(EnOutput, OUTPUT);
  pinMode(DirPin, OUTPUT);
  pinMode(StepPin, OUTPUT);
  pinMode(SW_RX, INPUT);
  pinMode(SW_TX, OUTPUT);
  //Set EnPin Default High
  digitalWrite(EnOutput, HIGH);
  TMCdriver.begin();
  TMCdriver.toff(5);
  TMCdriver.rms_current(900);
  TMCdriver.microsteps(256);
  TMCdriver.en_spreadCycle(false);
  TMCdriver.pwm_autoscale(true);
  Stepper.setMaxSpeed(1000);
  Stepper.setAcceleration(200);
}

void loop() {
  digitalWrite(EnOutput, digitalRead(EnInput));

  int UpSpeed = analogRead(UpPin);
  int DownSpeed = analogRead(DownPin);

  if(UpSpeed > 40) {
    digitalWrite(DirPin, LOW);
    while (analogRead(UpPin) > 40) {
      UpSpeed = analogRead(UpPin);
      float speed = map(UpSpeed, 0, 1023, 0, 1000);
      Stepper.setSpeed(UpSpeed);
      Stepper.runSpeed();
    }
    Stepper.setSpeed(0);
  }
 else if (DownSpeed > 40) {
  digitalWrite(DirPin, HIGH);
  while (analogRead(DownPin) > 40) {
    DownSpeed = analogRead(DownPin);
    float speed = map(DownSpeed, 0, 1023, 0, 1000);
    Stepper.setSpeed(DownSpeed);
    Stepper.runSpeed();
  }
  Stepper.setSpeed(0);
 } else {
  Stepper.setSpeed(0);
  Stepper.runSpeed();
 }
}

The begins are missing a zero. I don't think SoftwareSerial will do 115200.

That is about what I would expect, the software serial is not much good above 8600 baud.

I changed to 4800 on the software serial but I haven't felt much change in the microsteps or the run current. I change to 256 microsteps and the steps still feel like they are set at like 32 and if I set them to 8 it still feels like they are set to again 32. I'm not even sure if the config is even getting sent over and received. In the debug I added the current is changing but not the microsteps

here is the output im getting after putting in some debugging

image

Which is our dev board here ?

It says it supports baud rates from 9600 to 500000.
I've found they usually start at the lowest baud and have a setBaudRate function.
Try 9600 baud

1 Like

I still get a 256 microstep setting while the current changes as expected.

I'm using an arduino nano and a fysect 2209 v4.0 driver

This is in your code. ??
TMCdriver.microsteps(256);

1 Like

no my code says 2 microsteps but the driver is returning that it is set to 256 microsteps

image

I copied that from your code above.
2 is a good value for microsteps.
That's all I got.

#include <SoftwareSerial.h>
#include <TMCStepper.h>
#include <AccelStepper.h>

//Define Pins
//For LP:
//#define UpPin A0
//#define DownPin A1
//For DAC:
#define UpPin A2
#define DownPin A3
///===
#define EnInput 4
#define EnOutput 5
#define DirPin 2
#define StepPin 3

//Software Serial Setup Pin
#define SW_TX 7
#define SW_RX 8
#define DRIVER_ADDRESS 0b00
#define R_SENSE 0.11f

//TMCStepper Setup
SoftwareSerial UART(SW_RX, SW_TX);
TMC2209Stepper Driver(&UART, R_SENSE, DRIVER_ADDRESS);

//Accel Stepper Setup
AccelStepper Stepper(AccelStepper::DRIVER, StepPin, DirPin);

void setup() {
  pinMode(EnInput, INPUT);
  pinMode(EnOutput, OUTPUT);
  pinMode(DirPin, OUTPUT);
  pinMode(StepPin, OUTPUT);
  pinMode(SW_RX, INPUT);
  pinMode(SW_TX, OUTPUT);
  //Set EnPin Default High
  digitalWrite(EnOutput, HIGH);
  //Delay before Intialize
  delay(1000);
    //Intialize Driver if UART
  Driver.begin();
  Driver.toff(5);
  Driver.rms_current(900);
  Driver.microsteps(256);
  Driver.en_spreadCycle(false);
  Driver.pwm_autoscale(true);
  Stepper.setMaxSpeed(1000);
  Stepper.setAcceleration(200);
}

void loop() {
  digitalWrite(EnOutput, digitalRead(EnInput));

  int UpSpeed = analogRead(UpPin);
  int DownSpeed = analogRead(DownPin);

  if(UpSpeed > 40) {
    digitalWrite(DirPin, LOW);
    while (analogRead(UpPin) > 40) {
      UpSpeed = analogRead(UpPin);
      float speed = map(UpSpeed, 0, 1023, 0, 1000);
      Stepper.setSpeed(UpSpeed);
      Stepper.runSpeed();
    }
    Stepper.setSpeed(0);
  }
 else if (DownSpeed > 40) {
  digitalWrite(DirPin, HIGH);
  while (analogRead(DownPin) > 40) {
    DownSpeed = analogRead(DownPin);
    float speed = map(DownSpeed, 0, 1023, 0, 1000);
    Stepper.setSpeed(DownSpeed);
    Stepper.runSpeed();
  }
  Stepper.setSpeed(0);
 } else {
  Stepper.setSpeed(0);
  Stepper.runSpeed();
 }
}

this is the entire code but it still wants to set 256 microsteps no matter what I do to set it otherwise

The examples show you need to start the SoftwareSerial. The example shows 115200 baud, but SoftwareSerial is good to about 38400 baud reliably. On most boards 56Kbaud is the speed limit.

  //Delay before Intialize
  delay(1000);
    //Intialize Driver if UART

// add this
  UART.begin(9600);

  Driver.begin();

still no bueno nothing is getting set on the driver execept for the run current

image

im getting data sent and recieved according to the o-scope