Skip to content

Commit 92ad189

Browse files
committed
HardwareSerial setup for all microcontrollers
1 parent 0fcc661 commit 92ad189

File tree

5 files changed

+43
-58
lines changed

5 files changed

+43
-58
lines changed

.metadata/README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
* Library Information
1414
- Name :: TMC2209
15-
- Version :: 9.2.0
15+
- Version :: 9.3.0
1616
- License :: BSD
1717
- URL :: https://github.com/janelia-arduino/TMC2209
1818
- Author :: Peter Polidoro

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
- [Library Information](#orgfae7b95)
2-
- [Stepper Motors](#org35e24db)
3-
- [Stepper Motor Controllers and Drivers](#org1d27bfe)
4-
- [Communication](#org6470a96)
5-
- [Settings](#org283b3d3)
6-
- [Examples](#org596b863)
7-
- [Hardware Documentation](#org9cf2af8)
8-
- [Host Computer Setup](#org6a318a2)
1+
- [Library Information](#org14d03dc)
2+
- [Stepper Motors](#orgdd68c73)
3+
- [Stepper Motor Controllers and Drivers](#orgaf22ed8)
4+
- [Communication](#orgdf3ff08)
5+
- [Settings](#org9694a81)
6+
- [Examples](#orgf4511b6)
7+
- [Hardware Documentation](#org50a7c9b)
8+
- [Host Computer Setup](#orgd3aa6ed)
99

1010
<!-- This file is generated automatically from metadata -->
1111
<!-- File edits may be overwritten! -->
1212

1313

14-
<a id="orgfae7b95"></a>
14+
<a id="org14d03dc"></a>
1515

1616
# Library Information
1717

1818
- **Name:** TMC2209
19-
- **Version:** 9.2.0
19+
- **Version:** 9.3.0
2020
- **License:** BSD
2121
- **URL:** <https://github.com/janelia-arduino/TMC2209>
2222
- **Author:** Peter Polidoro
@@ -30,7 +30,7 @@ The TMC2209 is an ultra-silent motor driver IC for two phase stepper motors with
3030
<img src="./images/trinamic_wiring-TMC2209-description.svg" width="1920px">
3131

3232

33-
<a id="org35e24db"></a>
33+
<a id="orgdd68c73"></a>
3434

3535
# Stepper Motors
3636

@@ -41,7 +41,7 @@ A stepper motor, also known as step motor or stepping motor, is a brushless DC e
4141
[Wikipedia - Stepper Motor](https://en.wikipedia.org/wiki/Stepper_motor)
4242

4343

44-
<a id="org1d27bfe"></a>
44+
<a id="orgaf22ed8"></a>
4545

4646
# Stepper Motor Controllers and Drivers
4747

@@ -89,7 +89,7 @@ Another controller option is to use both a microcontroller and a separate step a
8989
<img src="./images/trinamic_wiring-TMC2209-stepper-controller.svg" width="1920px">
9090

9191

92-
<a id="org6470a96"></a>
92+
<a id="orgdf3ff08"></a>
9393

9494
# Communication
9595

@@ -391,7 +391,7 @@ A library such as the Arduino TMC429 library may be used to control the step and
391391
[Arduino TMC429 Library](https://github.com/janelia-arduino/TMC429)
392392

393393

394-
<a id="org283b3d3"></a>
394+
<a id="org9694a81"></a>
395395

396396
# Settings
397397

@@ -546,7 +546,7 @@ In voltage control mode, the hold current scales the PWM amplitude, but the curr
546546
In current control mode, setting the hold current is the way to adjust the stationary motor current. The driver will measure the current and automatically adjust the voltage to maintain the hold current, even with the operating conditions change. The PWM offset may be changed to help the automatic tuning procedure, but changing the hold current alone is enough to adjust the motor current since the driver will adjust the offset automatically.
547547

548548

549-
<a id="org596b863"></a>
549+
<a id="orgf4511b6"></a>
550550

551551
# Examples
552552

@@ -574,7 +574,7 @@ In current control mode, setting the hold current is the way to adjust the stati
574574
<https://github.com/janelia-kicad/trinamic_wiring>
575575

576576

577-
<a id="org9cf2af8"></a>
577+
<a id="org50a7c9b"></a>
578578

579579
# Hardware Documentation
580580

@@ -609,7 +609,7 @@ In current control mode, setting the hold current is the way to adjust the stati
609609
[Janelia Stepper Driver Web Page](https://github.com/janelia-kicad/stepper_driver)
610610

611611

612-
<a id="org6a318a2"></a>
612+
<a id="orgd3aa6ed"></a>
613613

614614
# Host Computer Setup
615615

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TMC2209
2-
version=9.2.0
2+
version=9.3.0
33
author=Peter Polidoro <[email protected]>
44
maintainer=Peter Polidoro <[email protected]>
55
sentence=The TMC2209 is an ultra-silent motor driver IC for two phase stepper motors with both UART serial and step and direction interfaces.

src/TMC2209.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,26 @@ class TMC2209
3131
SERIAL_ADDRESS_2=2,
3232
SERIAL_ADDRESS_3=3,
3333
};
34-
// Alternate rx and tx pins may be specified for certain microcontrollers e.g.
35-
// ESP32 and RP2040
36-
#if defined(ESP32)
37-
void setup(HardwareSerial & serial,
38-
long serial_baud_rate=115200,
39-
SerialAddress serial_address=SERIAL_ADDRESS_0,
40-
int16_t alternate_rx_pin=-1,
41-
int16_t alternate_tx_pin=-1);
42-
#elif defined(ARDUINO_ARCH_RP2040)
43-
void setup(HardwareSerial & serial,
44-
long serial_baud_rate=115200,
45-
SerialAddress serial_address=SERIAL_ADDRESS_0);
46-
void setup(SerialUART & serial,
47-
long serial_baud_rate=115200,
48-
SerialAddress serial_address=SERIAL_ADDRESS_0,
49-
int16_t alternate_rx_pin=-1,
50-
int16_t alternate_tx_pin=-1);
51-
#else
5234
// Identify which microcontroller serial port is connected to the TMC2209 e.g.
5335
// Serial1, Serial2, etc. Optionally identify which serial address is assigned
5436
// to the TMC2209 if not the default of SERIAL_ADDRESS_0.
5537
void setup(HardwareSerial & serial,
5638
long serial_baud_rate=115200,
5739
SerialAddress serial_address=SERIAL_ADDRESS_0);
40+
// Alternate rx and tx pins may be specified for certain microcontrollers e.g.
41+
// ESP32 and RP2040
42+
#if defined(ESP32)
43+
void setup(HardwareSerial & serial,
44+
long serial_baud_rate,
45+
SerialAddress serial_address,
46+
int16_t alternate_rx_pin,
47+
int16_t alternate_tx_pin);
48+
#elif defined(ARDUINO_ARCH_RP2040)
49+
void setup(SerialUART & serial,
50+
long serial_baud_rate,
51+
SerialAddress serial_address,
52+
int16_t alternate_rx_pin,
53+
int16_t alternate_tx_pin);
5854
#endif
5955

6056
#if SOFTWARE_SERIAL_INCLUDED

src/TMC2209/TMC2209.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ TMC2209::TMC2209()
1919
cool_step_enabled_ = false;
2020
}
2121

22+
void TMC2209::setup(HardwareSerial & serial,
23+
long serial_baud_rate,
24+
SerialAddress serial_address)
25+
{
26+
hardware_serial_ptr_ = &serial;
27+
hardware_serial_ptr_->end();
28+
hardware_serial_ptr_->begin(serial_baud_rate);
29+
30+
initialize(serial_baud_rate, serial_address);
31+
}
2232
#if defined(ESP32)
2333
void TMC2209::setup(HardwareSerial & serial,
2434
long serial_baud_rate,
@@ -41,16 +51,6 @@ void TMC2209::setup(HardwareSerial & serial,
4151
initialize(serial_baud_rate, serial_address);
4252
}
4353
#elif defined(ARDUINO_ARCH_RP2040)
44-
void TMC2209::setup(HardwareSerial & serial,
45-
long serial_baud_rate,
46-
SerialAddress serial_address)
47-
{
48-
hardware_serial_ptr_ = &serial;
49-
hardware_serial_ptr_->end();
50-
hardware_serial_ptr_->begin(serial_baud_rate);
51-
52-
initialize(serial_baud_rate, serial_address);
53-
}
5454
void TMC2209::setup(SerialUART & serial,
5555
long serial_baud_rate,
5656
SerialAddress serial_address,
@@ -73,17 +73,6 @@ void TMC2209::setup(SerialUART & serial,
7373

7474
initialize(serial_baud_rate, serial_address);
7575
}
76-
#else
77-
void TMC2209::setup(HardwareSerial & serial,
78-
long serial_baud_rate,
79-
SerialAddress serial_address)
80-
{
81-
hardware_serial_ptr_ = &serial;
82-
hardware_serial_ptr_->end();
83-
hardware_serial_ptr_->begin(serial_baud_rate);
84-
85-
initialize(serial_baud_rate, serial_address);
86-
}
8776
#endif
8877

8978
#if SOFTWARE_SERIAL_INCLUDED

0 commit comments

Comments
 (0)