teemuatlut / TMC2130Stepper

Arduino library for Trinamic TMC2130 Stepper driver
MIT License
158 stars 50 forks source link

Issue with multiple TMC2130 #67

Closed akym closed 5 years ago

akym commented 5 years ago

I am using 3 TMC2130 with Teensy3.6 with SoftwareSPI. After cutting the power off to uC and drivers and turning it back again, the code doesn't work. I have to upload a stripped down version of code where I initialize only 1 driver at a time, I have to do this two times and then lastly upload the main code I want and it works perfectly fine. I don't know what's causing this issue, any ideas? Is it something to do with SoftwareSPI? Is there a piece of code in the library where I can reset the TMC2130s and then initialize them again? Do I need to move all drivers to hardware SPI? I am confused, I have tried reading previous similar experiences and tried with their solution with no luck. Any help is appreciated.

I posted the same problem on the Teensy forum as well, code and schematic are attached there. https://forum.pjrc.com/threads/55022-Problem-with-multiple-slave-SPI

teemuatlut commented 5 years ago

This might be quite difficult to debug. You can make use of test_connection(). Another thing to try is using the newer TMCStepper library.

  pinMode(MISO_PIN, INPUT_PULLUP);
  pinMode(MISO_PIN1, INPUT_PULLUP);
  pinMode(MISO_PIN2, INPUT_PULLUP);

This doesn't do anything as it is already part of begin, when SW SPI is used.

SPI.begin(); This is not necessary for SW SPI because it doesn't use the SPI port. With HW SPI it is called automatically on every read or write.

I'd suggest you strip down your sketch to just initializing the three drivers and making sure that the registers read as expected. I'd like to know what "code doesn't work" means in more detail. Is it that the communication doesn't work, or if the driver doesn't get initialized properly, or maybe something else. Try to narrow down your issue.

Personally I'd also use HW SPI or at least use the same SW SPI pins. There's no reason for each to have individual MISO/MOSI/SCK pins. Only the CS needs to be unique. But that probably is not the cause of your issues as it should still work. Also you're the first I've heard using the library with the Teensy platform. Best of luck and let me know of your progress!

akym commented 5 years ago

Thanks for the reply. I believe sudden interruption in power supply to both Teensy and the drivers leaves the drivers in an unknown state. And on next boot, the drivers don't get initialized properly.
I understand that all pins need not be unique for SW_SPI but it is done for the backward compatibility and the whole setup is mounted on 2 routed PCBs. So to use Hardware SPI, I would need to manually jump the pins. I will further try to debug this issue or just do the Hardware SPI.

Teensy works great for the setup as I need a lot of pins for the system with some fast computing.

I will further keep you posted of any solution I find.

teemuatlut commented 5 years ago

If you cut all the power (VMOT and VIO) then the driver will restart with default registers.

akym commented 5 years ago

So the solution was to take out the backward compatibility(for other motor drivers) and share the SPI lines for all 3 drivers. Now it works without a problem.