-
Notifications
You must be signed in to change notification settings - Fork 52
TMC2209 in UART #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If using a single pin for communication then a soft UART has to be implemented, at least for one direction? Or you have to remap the pin on the fly as TX or RX as required? |
Hi @terjeio . PDN_UART pin is being used on BTT 2209's. Other stepper manufacturers like FYSETC may pull these pins out separately and provide the 1k resistor. It's probably built into the TMC UART libraries and the TMC drivers. I just don't see the way it should be implemented with your code yet. |
The current TMC UART driver code supports the connection mode shown above and uses the secondary UART channel for communication. It is possible to use a single pin for RX/TX either by adding soft UART support or remapping a hardware UART pin between sending and receiving messages (if possible) - code has to be added for that. This code would then be an alternative to the current TMC UART driver code. |
Hi @terjeio awesome, but it's still not clear how to implement. Do you have a specific set of settings in CMakeList.txt and _map.h which includes the necessary settings? Example... I'm sure I've missed many of the settings. |
In your map file:
If your board is supporting more than one driver type then enabling TMC2209 should be added to CMakeLIsts.txt as an option instead. |
Hi @terjeio I would like to use a common pin for all drivers (using MS1/MS2 to set the addresses). Is this possible and what is the syntax. |
What exactly do you mean by "a common pin" - one common pin for both TX and RX or separate pins for RX and TX as shown in the schematic above? Both is possible but the first option (one common pin) will require additional code. |
All drivers (up to 4) wired in parallel to the same pair of pins (single TX pin and a single RX pin), then each driver requires an address. Each address is set by the MS1/MS2 for that driver. For instance X driver is address 0, MS1/MS2 are left open. Y driver address is 1, MS1 is set high, MS2 is open. How are the addresses designated in your code? |
Ok, I got confused by your wording - I was thinking you wanted to use a single pin for both TX and RX.
All has to be addressed as driver 0 when using MS1/MS2- but the current ESP code does not support that. Easy to fix though, by adding a few lines of code - same as done in the STM32F4xx driver. Current code support up to four drivers, the drivers will be addressed in the transmitted messages. This is the STM32F4xx code , bits from that has to be added to trinamic_if.c at line 221:
and at line 240:
I guess I should add this as a compile time option... |
Hi @terjeio, unfortunately making only these changes in _map.h results in this compilation error. I have not yet confirmed the changes to trinamic_if.c. Thank you! [1293/1294] Linking CXX executable grbl.elf |
Have you modified CMakeLists.txt to enable TMC2209 support? I keep forgetting that this file has to be modified to add the relevant source code. |
Thank you! snipped ... |
I have just uploaded a new build that compiles for me (but I have not tested it). Lines 36 to 37 in 8e2c64d
You have to add
An example:
Normally you do not have to change these files unless fine tuning parameters. Getting stallguard to work properly is not easy, I strongly recommend that you read up on that in the datasheet/manual. |
Hi @terjeio, I will be testing soon. It seems that in CMakeLists.txt you called it TMC2209_HWADDR, but in trinamic_if.c you're using TRINAMIC_UART_HWADDR. |
If you look further down in the file you can see that the options are used to set compiler symbols used in the code.
Yes. |
Hi @terjeio, yes it compiles. However, when attempting to set $338 (and $339) it indicates no communication to the driver. With less sophisticated firmware, I've verified the drivers are communicating and can see the diag pin go high when a stall is detected so I believe the wiring is correct. For debug I used a single driver only on X, and cannot set $338=1 due to the communications error. |
Is there any output on the TX pin on startup? I assume you have your own board map, I can try debugging if you add it to a comment (zipped please). |
I have now run some tests - and it is the UART that is misbehaving (there is another crazy guru in there?). |
Hi @terjeio,
This is the UART2 trace at startup This is the UART2 trace after issuing M122I When Trinamic UART communications not working Thank you! |
Is the driver motor power on at this point? The drivers are unresponsive if not.
Odd, is both the driver and the MCU trying to transmit simultaneously? I've did not see such a trace when I debugged. The response on reading from a driver is always 8 bytes, and with the code changes I made this never failed (many hundreds of
I suspect the random failures I had is due to the driver receiving a corrupted message and the check I have on startup for the transaction count is failing. Or a CRC check on the response fails... Both are in the TMC2209 code and is where I desperately want to set breakpoints and inspect values. |
I power up the MCU and drivers simultaneously. Bad things happen to the ESP devices if they get power from USB, then from a main board powering motors. So I'm forced to power up both simultaneously, but for debug I will try to power up the drivers first, then the MCU.
I don't know. But it is possible. Currently I'm locked out of UART communications and cannot get back in. I always get the 3rd trace when issuing the M122I command and get this error when trying to set $338 [MSG:Warning: Could not communicate with stepper driver!]. So I'm locked out for now and double checking all my wiring. TMC datasheet does say we have to keep the communications below 500k without a clock and I believe you limited it to about half that in trinamic_if.c. I'll do more testing and report back. |
Hi @terjeio I found that the issues is likely related to addressing. Single axis works for X, with only sometimes communications error on M122I command. If the Y axis UART pin is connected it will give communications error 100% of the time and will not set do simple things like set microstepping regardless of $338 set to 1 or addressing off. When I disconnect the Y driver UART wire I can again communicate with UART on X axis. I verified that the Y driver UART works when installed in the X axis slot and it's the only driver installed. Also as far as wiring, I've made sure that Is the code looking for responses only from motors defined by $338? I would expect that it should only attempt to communicate with defined motors. Thank you! |
$338 set to 1 enables the X motor, 2 enables the Y motor...
Yes I think so - but with hardware adressing it is not possible for code to know which one is responding. With software addressing the CRC check of the response message will fail as the slave address is part of the response (IIRC).
Correct. |
Are you running the drivers with 5V VIO? The ESP32 is a 3.3V device and not 5V tolerant. |
Hi @terjeio, I had previously tried 3.3V VIO, but hard limits were not triggering, so I reverted to 5V. With the correct wiring That weird trace would show 3.3V coming from the controller and 3.3-5V signal coming from the driver (not 0-5V). With the updated code and 3.3V VIO I now get these results using addressing and only X Y installed. Thank you! |
Forgive me if I have misunderstood your question, but could you not use JTAG ? eg |
I found a bug in the TMC2209 driver code that will affect repeated initializations, but I forgot to update this issue. Sorry about that. And I have implemented the TMC2209_HWADDR option the wrong way around?
The ESP32 boards I have does not have a JTAG or SWD connector, are there any boards available that has? Without limiting the number of available GPIO pins? |
@terjeio thank you for updating this issue. I will report back my findings in a few days as I have hardware now I can test with that no longer looks like this. |
Issue resolved. Thank you. |
Uh oh!
There was an error while loading. Please reload this page.
I'm using BigTree Tech 2209s. The User Manual for this 2209 informs to use the solder jumper to enable UART on the driver pin for TX and a 1k ohm resistor on that same pin for RX. I have a limited number of available pins on the ESP32 (not using any IO expansion) and I would like to use a common pin for all drivers (using MS1/MS2 to set the addresses). I don't really see how to configure this as no option in CMakeLists.txt and no examples.
The text was updated successfully, but these errors were encountered: