-
Notifications
You must be signed in to change notification settings - Fork 43
Description
I have 3 x BTT TMC2209 drivers connected to hardware uart Serial1 (GPIO 0 & 1) on a Pi Pico W v1 (RP2040). Each has MS1 and MS2 pins set so they are addressed 0, 1 and 2. RX and TX are on a Y connection with a 1k resistor on the TX pin as shown in your excellent documentation. The drivers have 15v on VM, and 3.3v on VIO. The stepper motors attached to the drivers all work OK when I drive them with the AccelStepper library.
My problem is I can only get 1 (sometimes 2, and very occasionally 3) to successfully complete setup. If I switch around the order I initialise them, ALL of them work if they are initialised first, but the third one to be initialised usually reports as not setup.
For example:
#include <TMC2209.h>
const long SERIAL_BAUD_RATE = 115200;
HardwareSerial & driver_uart = Serial1;
TMC2209 driver_L;
TMC2209 driver_R;
TMC2209 driver_C;
const TMC2209::SerialAddress SERIAL_ADDRESS_L = TMC2209::SERIAL_ADDRESS_0;
const TMC2209::SerialAddress SERIAL_ADDRESS_R = TMC2209::SERIAL_ADDRESS_1;
const TMC2209::SerialAddress SERIAL_ADDRESS_C = TMC2209::SERIAL_ADDRESS_2;
const uint8_t REPLY_DELAY = 4;
...
void setup() {
...
}
void setup1() {
Serial.begin(SERIAL_BAUD_RATE);
delay(2000);
Serial.println();
driver_L.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_L);
driver_L.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_L: communicating: %d, and setup: %d\n", driver_L.isCommunicating(), driver_L.isSetupAndCommunicating());
driver_R.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_R);
driver_R.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_R: communicating: %d, and setup: %d\n", driver_R.isCommunicating(), driver_R.isSetupAndCommunicating());
driver_C.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_C);
driver_C.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_C: communicating: %d, and setup: %d\n", driver_C.isCommunicating(), driver_C.isSetupAndCommunicating());
}
Gives:
driver_L: communicating: 1, and setup: 1
driver_R: communicating: 1, and setup: 0
driver_C: communicating: 1, and setup: 0
If I switch the order the of initialisation to R, then L, C like this:
driver_R.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_R);
driver_R.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_R: communicating: %d, and setup: %d\n", driver_R.isCommunicating(), driver_R.isSetupAndCommunicating());
driver_L.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_L);
driver_L.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_L: communicating: %d, and setup: %d\n", driver_L.isCommunicating(), driver_L.isSetupAndCommunicating());
driver_C.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_C);
driver_C.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_C: communicating: %d, and setup: %d\n", driver_C.isCommunicating(), driver_C.isSetupAndCommunicating());
Gives:
driver_R: communicating: 1, and setup: 1
driver_L: communicating: 1, and setup: 1
driver_C: communicating: 0, and setup: 0
And if I change the order again to C, L, R like this:
driver_C.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_C);
driver_C.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_C: communicating: %d, and setup: %d\n", driver_C.isCommunicating(), driver_C.isSetupAndCommunicating());
driver_R.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_R);
driver_R.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_R: communicating: %d, and setup: %d\n", driver_R.isCommunicating(), driver_R.isSetupAndCommunicating());
driver_L.setup(driver_uart, SERIAL_BAUD_RATE,SERIAL_ADDRESS_L);
driver_L.setReplyDelay(REPLY_DELAY);
Serial.printf("driver_L: communicating: %d, and setup: %d\n", driver_L.isCommunicating(), driver_L.isSetupAndCommunicating());
Gives:
driver_C: communicating: 1, and setup: 1
driver_R: communicating: 1, and setup: 0
driver_L: communicating: 1, and setup: 0
So each one works on its own serial address when setup first, but subsequent drivers usually fail to setup correctly. This result is not 100% consistent. As I was writing this post, changing the order of the code and uploading to copy the results, twice all three showed setup successful, but then I powered off the Pico, and tested again, and I was back to only the first one completing setup. I've tried making the reply delay longer and shorter but the result is the similar.
Any ideas?