TMCStepper icon indicating copy to clipboard operation
TMCStepper copied to clipboard

just one connected TMC2209 with add.0b00 worked and the other 0b11 didn't work

Open brainhasan opened this issue 2 years ago • 4 comments

I want to connect 2 TMC2209 to arduino , when i send 1 in serial just one stepper worked wich have address 0b00 the otherone with ADD 0b11 not worked , however MS1 MS2 with Vio for Add 0b11

this is the code wich i used ( edited )

`/**

  • Author Teemu Mäntykallio
  • Plot TMC2130 or TMC2660 motor load using the stallGuard value.
  • You can finetune the reading by changing the STALL_VALUE.
  • This will let you control at which load the value will read 0
  • and the stall flag will be triggered. This will also set pin DIAG1 high.
  • A higher STALL_VALUE will make the reading less sensitive and
  • a lower STALL_VALUE will make it more sensitive.
  • You can control the rotation speed with
  • 0 Stop
  • 1 Resume
    • Speed up
    • Slow down */ #include <TMCStepper.h>

#define MAX_SPEED 40 // In timer value #define MIN_SPEED 1000

#define STALL_VALUE 100 // [0..255]

#define EN_PIN 2 // Enable #define DIR_PIN 3// Direction #define STEP_PIN 4 // Step #define SW_RX 7 // TMC2208/TMC2224 SoftwareSerial receive pin #define SW_TX 6 // TMC2208/TMC2224 SoftwareSerial transmit pin //#define SERIAL_PORT Serial1 // TMC2208/TMC2224 HardwareSerial port #define DRIVER_ADDRESS 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

// Select your stepper driver type //TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS); TMC2209Stepper driver(SW_RX, SW_TX, R_SENSE, DRIVER_ADDRESS);

using namespace TMC2208_n;

// Using direct register manipulation can reach faster stepping times #define STEP_PORT PORTF // Match with STEP_PIN #define STEP_BIT_POS 0 // Match with STEP_PIN

#define EN_PIN_1 8 // Enable #define DIR_PIN_1 13// Direction #define STEP_PIN_1 10 // Step #define SW_RX_1 11 // TMC2208/TMC2224 SoftwareSerial receive pin #define SW_TX_1 12 // TMC2208/TMC2224 SoftwareSerial transmit pin //#define SERIAL_PORT Serial1 // TMC2208/TMC2224 HardwareSerial port #define DRIVER_ADDRESS_1 0b11 // TMC2209 Driver address according to MS1 and MS2 #define R_SENSE_1 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

// Select your stepper driver type //TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS); TMC2209Stepper driver1(SW_RX_1, SW_TX_1, R_SENSE_1, DRIVER_ADDRESS_1);

ISR(TIMER1_COMPA_vect){ //STEP_PORT ^= 1 << STEP_BIT_POS; digitalWrite(STEP_PIN, !digitalRead(STEP_PIN));

}

void setup() { Serial.begin(115200); // Init serial port and set baudrate while(!Serial); // Wait for serial port to connect Serial.println("\nStart...");

// SERIAL_PORT.begin(115200); driver.beginSerial(115200); driver1.beginSerial(115200);

pinMode(EN_PIN, OUTPUT); pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); digitalWrite(EN_PIN, LOW);

pinMode(EN_PIN_1, OUTPUT); pinMode(STEP_PIN_1, OUTPUT); pinMode(DIR_PIN_1, OUTPUT); digitalWrite(EN_PIN_1, LOW);

driver.begin(); driver.toff(4); driver.blank_time(24); driver.rms_current(2000); // mA driver.microsteps(16); driver.TCOOLTHRS(0xFFFFF); // 20bit max driver.semin(5); driver.semax(2); driver.sedn(0b00); driver.SGTHRS(STALL_VALUE); driver.microsteps(16); // Set microsteps

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

// Set stepper interrupt

driver1.begin(); driver1.toff(4); driver1.blank_time(24); driver1.rms_current(2000); // mA driver1.microsteps(16); driver1.TCOOLTHRS(0xFFFFF); // 20bit max driver1.semin(5); driver1.semax(2); driver1.sedn(0b11); driver1.SGTHRS(STALL_VALUE); driver1.microsteps(16); // Set microsteps

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

driver.shaft(true); digitalWrite( EN_PIN, HIGH );

driver1.shaft(true); digitalWrite( EN_PIN_1, HIGH );

{ cli();//stop interrupts TCCR1A = 0;// set entire TCCR1A register to 0 TCCR1B = 0;// same for TCCR1B TCNT1 = 0;//initialize counter value to 0 OCR1A = 256;// = (1610^6) / (11024) - 1 (must be <65536) // turn on CTC mode TCCR1B |= (1 << WGM12); // Set CS11 bits for 8 prescaler TCCR1B |= (1 << CS11);// | (1 << CS10); // enable timer compare interrupt TIMSK1 |= (1 << OCIE1A); sei();//allow interrupts }

}

void loop() { static uint32_t last_time=0; uint32_t ms = millis();

while(Serial.available() > 0) { int8_t read_byte = Serial.read(); #ifdef USING_TMC2660 if (read_byte == '0') { TIMSK1 &= ~(1 << OCIE1A); driver.toff(0); } else if (read_byte == '1') { TIMSK1 |= (1 << OCIE1A); driver.toff(driver.savedToff()); } #else if (read_byte == '0') { TIMSK1 &= ~(1 << OCIE1A); digitalWrite( EN_PIN, HIGH );digitalWrite( EN_PIN_1, HIGH ); } else if (read_byte == '1') { TIMSK1 |= (1 << OCIE1A); digitalWrite( EN_PIN, LOW );digitalWrite( EN_PIN_1, LOW ); } #endif else if (read_byte == '+') { if (OCR1A > MAX_SPEED) OCR1A -= 20; } else if (read_byte == '-') { if (OCR1A < MIN_SPEED) OCR1A += 20; } else if (read_byte == 'u'){ //digitalWrite(DIR_PIN, LOW);delay(3000); digitalWrite(EN_PIN, HIGH);delay(3000); digitalWrite(EN_PIN, LOW);
driver.shaft(false); // digitalWrite(EN_PIN, LOW); for (uint16_t i = 5000; i>0; i--) { digitalWrite(STEP_PIN, HIGH); delayMicroseconds(100); digitalWrite(STEP_PIN, LOW); delayMicroseconds(100);

} digitalWrite(EN_PIN, HIGH); delay(3000);digitalWrite(EN_PIN, LOW); driver.shaft(true); } }

if((ms-last_time) > 100) { //run every 0.1s last_time = ms;

}

}`

brainhasan avatar Oct 20 '22 08:10 brainhasan

You are using TMC2208 namespace using namespace TMC2208_n;

cranefist avatar Oct 31 '22 18:10 cranefist

So this looks like the default Stallguard example and then you added pins in the code for a second TMC2209 stepper driver and motor. But when you run the code the originally coded motor spins but the one you added doesn't (?). Did I get that right?

Reading your code it looks like you assigned the "second" motor to #define EN_PIN_1 8 // Enable #define DIR_PIN_1 13// Direction #define STEP_PIN_1// Step . But looking through your code I don't see any digitalWrite(STEP_PIN_1, HIGH); and then to low. Only for STEP_PIN do you have that. And also the example spins the motor via this timed function

ISR(TIMER1_COMPA_vect){ //STEP_PORT ^= 1 << STEP_BIT_POS; digitalWrite(STEP_PIN, !digitalRead(STEP_PIN)); } Possibly adding digitalWrite(STEP_PIN_1, !digitalRead(STEP_PIN_1)); might get the second motor to move.

And while I haven't been trying to run two motors, I've been running the Stallguard example with the TMC2208_n; namespace for a single TMC2209 and it works and gives me the data I need.

Those are some starting points I'd have given what I can put together.

TrulyMarcus avatar Nov 03 '22 02:11 TrulyMarcus

Is it possible to run two drivers with one hardware serial port? (Using only one UX & TX pins)

sidn007 avatar Mar 17 '23 17:03 sidn007

TMC2209 uses a communication frame on top of UART which lets up to 4 TMC2209s to be controlled using single UART connection. Checkout TMC2209 datasheet for more information.

SobhanAbedi avatar Mar 17 '23 17:03 SobhanAbedi