Issues running SW UART for a motor and I2C for an RTC at same time

I am building a clock with a stepper motor running on a TMC2209 driver with a Sparkfun RV-8803 rtc on a Sparkfun Pro Micro.

I got the motor running finally, but I have hit a big wall with getting the RTC to play nice with it. Any time I uncomment the lines using the RTC such as

//Wire.begin();
//rtc.begin();
//or
//rtc.updateTime();

The motor stops running and makes some fun noises. Is this from some sort of conflict with I2C and my SW UART?

Thanks for looking at this.

//runs stepper motor


#include <TMCStepper.h>      // TMCstepper - https://github.com/teemuatlut/TMCStepper
#include <SoftwareSerial.h>  // Software serial for the UART to TMC2209 - https://www.arduino.cc/en/Reference/softwareSerial
#include <Streaming.h>       // For serial debugging output - https://www.arduino.cc/reference/en/libraries/streaming/

#define EN_PIN 2             // Enable - PURPLE
#define DIR_PIN 3            // Direction - WHITE
#define STEP_PIN 4           // Step - ORANGE
#define SW_SCK 5             // Software Slave Clock (SCK) - BLUE
#define SW_TX 6              // SoftwareSerial receive pin - BROWN
#define SW_RX 7              // SoftwareSerial transmit pin - YELLOW
#define DRIVER_ADDRESS 0b00  // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f        // SilentStepStick series use 0.11 ...and so does my fysetc TMC2209 (?)

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

#include <SparkFun_RV8803.h> //Get the library here:http://librarymanager/All#SparkFun_RV-8803

RV8803 rtc;


int accel;
long maxSpeed;
int speedChangeDelay;
bool dir = true;


int numTeethClock = 240;
int numTeethMotor = 30;

int lastHundred = 0;
int timeCheck = 0;
int mStepsPerRotation = 51200;


//== Setup ===============================================================================

void setup() {

  Serial.begin(115200);           // initialize hardware serial for debugging
  SoftSerial.begin(115200);       // initialize software serial for UART motor control
  TMCdriver.beginSerial(115200);  // Initialize UART
  //115200
  //9600
  pinMode(EN_PIN, OUTPUT);  // Set pinmodes
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW);  // Enable TMC2209 board

  TMCdriver.begin();           // UART: Init SW UART (if selected) with default 115200 baudrate
  TMCdriver.toff(5);           // Enables driver in software
  TMCdriver.rms_current(500);  // Set motor RMS current
  TMCdriver.microsteps(256);   // Set microsteps

  TMCdriver.en_spreadCycle(false);
  TMCdriver.pwm_autoscale(true);  // Needed for stealthChop
  TMCdriver.shaft(dir);

// rtc address: 0x64
 //Wire.begin();   --------------------------NEEDED FOR RTC
 //rtc.begin();      --------------------------NEEDED FOR RTC

  //calculate delay between steps


}

//== Loop =================================================================================

void loop() {

  //get time update
  //rtc.updateTime();        --------------------------NEEDED FOR RTC
  // timeCheck = rtc.getHundredths();
  // if(timeCheck != lastHundred){
  //   lastHundred = timeCheck;
  // }


  // for (uint16_t i = 12800; i > 0; i--) { //microsteps
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(69); //70-69 too fast 70-70 too slow
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(70);
  // }

  //dir = !dir;  // REVERSE DIRECTION


  
}

SoftwareSerial does not tolerate interrupts from other I/O, like interrupt driven I2C. Use the hardware serial port on the Pro Micro instead.

Keep in mind that you also can't have two instances of SoftwareSerial listening at the same time (not sure if that applies to the motor driver, but I do see two .begin() calls).

Thanks, yeah I think I will just have to run this stepper not using UART. That should fix it.

Or use the hardware serial port Serial1.

No now I am just trying to run the stepper step by step without any UART, but still uncommenting those same lines stops the motor from moving. Any ideas on what is going on?

//runs stepper motor

#define EN_PIN 2             // Enable - PURPLE
#define DIR_PIN 3            // Direction - WHITE
#define STEP_PIN 4           // Step - ORANGE

#include <SparkFun_RV8803.h> //Get the library here:http://librarymanager/All#SparkFun_RV-8803

RV8803 rtc;


int accel;
long maxSpeed;
int speedChangeDelay;
bool dir = true;


int numTeethClock = 240;
int numTeethMotor = 30;

int lastHundred = 0;
int timeCheck = 0;
int mStepsPerRotation = 51200;


//== Setup ===============================================================================

void setup() {

  pinMode(EN_PIN, OUTPUT);  // Set pinmodes
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW);  // Enable TMC2209 board

// rtc address: 0x64
 //Wire.begin(); ----------------------This stops the motor
 //rtc.begin(); ----------------------This stops the motor

}

//== Loop =================================================================================

void loop() {
    digitalWrite(STEP_PIN, HIGH);
    delay(10);
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(70);
    delay(10);
}


I2C is hanging up the system for some reason. Make sure that pin definitions don't overlap.

Start with the first example in the Sparkfun library and make sure the RTC works with no hardware or libraries, other than required.

Then add the stepper motor code to that, bit by bit, testing as you go.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.