As mentioned in the last post TMC2300-IOT-REF - Remote controlled Stepper Motor - Getting to blink there was an issue with the connector on the motor. I found a grove connector was about the right size if I trimmed it slightly so I soldered that on.
Get your motor running
The next thing to try is to have the motor running. For this there are a few steps needed. Firstly to provide some power then to send the right serial commands to the controller chip and the finally to enable motor output.
The supply to the motor is connected to +VBAT, this in turn is connected to the charger circuit. The AN058 tech note suggests you can use a power supply to power the motor.
Serial communication is covered in section 4 of the tmc3200 data sheet and Jan Cumps also did a detailed look at the serial comms for a previous road test, Trinamic Stepper Motor Controller TMC2300 - UART Interface Jan also references a library which looks like it could be useful https://github.com/trinamic/TMC-API
The key part of the serial communications is that the commands to send to the motor are wrapped in a special data structure for error checking and addressing. The address is configured via AD0 and AD1 pins, in this reference design these are both tied to ground so it would be address zero. The algorithm for the CRC is also included in the notes but the is a practical example for the code in the blynk example. https://github.com/trinamic/TMC2300-IOT-REF/blob/master/Blynk/Stepper_Mode
The enable pin can also be found in the schematic on pin 32 and this is confirmed by the code example.
I copied in the TMC_2300.ino, CRC.ino and include files from the Blynk example. I was initially puzzled why the libraries were named with the INO suffix, but that allows the Arduino IDE to compile the files with the right headers so TMC_2300.ino can find Serial1 without needing to reference the Arduino header files. You just need to ensure you open the right ino to for your project. In my case "MotorRun.ino"
Checking the Blynk document we can see that the speed value is between 500 and 9000, and the current is between 9 and 31. So I plugged those values straight into the code.
#include "include/Functions.h" #include "include/TMC2300.h" #include "include/CRC.h" #define LED_STATUS 18 #define MOTOR_EN 32 void setup() { pinMode(LED_STATUS, OUTPUT); pinMode(MOTOR_EN, OUTPUT); // Debug console Serial.begin(115200); // TMC2300 IC UART connection Serial1.begin(115200); // Initialize CRC calculation for TMC2300 UART datagrams tmc_fillCRC8Table(0x07, true, 0); // Set the speed to 7000 tmc2300_writeInt(TMC2300_VACTUAL, 7000); // Set the current limit to 31 (default) uint32_t value = 1 << TMC2300_IHOLDDELAY_SHIFT | ((31 << TMC2300_IRUN_SHIFT) & TMC2300_IRUN_MASK) | 8 << TMC2300_IHOLD_SHIFT; tmc2300_writeInt(TMC2300_IHOLD_IRUN, value); // Enable the motor digitalWrite(MOTOR_EN, HIGH); Serial.print("Initialisation Complete"); } void loop() { // Toggle the status LED while the motor is active digitalWrite(18, HIGH); delay(250); digitalWrite(18, LOW); delay(250); digitalWrite(18, HIGH); delay(250); digitalWrite(18, LOW); // Re-write the CHOPCONF register periodically tmc2300_writeInt(TMC2300_CHOPCONF, 0x14008001); }
The LED is still flashing nicely but no response from the motor. Possible causes include the motor wiring, power supply, Trinamic's code, my code.
I cross checked the wiring and confirmed that there was one coil of the motor connected to pins 1 and 2 and the other to pins 3 and 4. However, looking at the datasheet in more detail vs the pinouts on the board, I spotted that the A coil was reversed, I'd still expect some kind of motion from the motor with that configuration but I swapped the connectors just to check. And still no motor movement.
To check if power was an issue, I plugged in the board directly to a charger. Again, flashing lights but no motion. Looking at the schematic the diag pin is connected to a white led and would illuminate when there was a driver error or stall. This was not the case.
So my next thought was to use the serial interface to query the state of the chip and see if I could diagnose what was going on.
Serial Reading
Looking at the datasheet there were 3 registers that seemed of interest. GSTAT, GCONF and IOIN. So I updated the code to read these using the read int function and a simple display function
void printByte(uint8_t var) { for (uint8_t test = 0x80; test; test >>= 1) { Serial.write(var & test ? '1' : '0'); } Serial.println(); } void loop() { delay(1000); result = tmc2300_readInt(TMC2300_GCONF); Serial.print("GCONF:"); printByte(result); result = tmc2300_readInt(TMC2300_GSTAT); Serial.print("GSTAT:"); printByte(result); result = tmc2300_readInt(TMC2300_IOIN); Serial.print("IOIN:"); printByte(result); }
These all returned zero which made me suspect that it wasn't communicating with the TMC2300 correctly, but I double checked by adding IHOLD_IRUN and CHOPCONF which also came back as zero.
Next up I set the speed for the serial communication lower to 57600, that also made no difference.
One thing I didn't try was to see if there was an issue with the CRC. Looking at the code in TMC2300.INO there is a line that returns zero if the CRC does not tally. So that might be something to try.
Back to basics
Scouring the data sheet for the reference board, I spotted that the step and direction pins were connected to the ESP32. So I tried a simple sketch that pulsed the step pin and the motor did turn. However the motor got quite warm, quite quickly so I reflashed to a simple blink sketch.
So this does demonstrate that at least the motor is wired up correctly.
CAUTION: Do not simply pulse the step pin, that can overload the board.
At this point I decided to take a break as the board had got quite warm too.
Damaged?!
After leaving it an hour, I decided to try it again. If I power it up either from the battery or from USB the LED blinks so the ESP32 is obviously getting power. But the board is no longer detected as a serial port by the computer. The area ringed below gets very hot. One of the other roadtesters mentioned an under voltage condition which got me thinking that I may have just discharged the battery. So I checked that and the battery voltage seems a little high, am getting 3.9v on the connector on the edge of the board. The overheating happens regardless of if the battery is attachd or the USB or both. Also the the board is not recognise by the PC.
It is possible that this is caused by software e.g. the TMC2300 is still trying to draw a massive current on startup. Or it could be that the previous experiments damaged the battery charge/power regulation stage?
Backup Plan
I've devised a backup plan. It might not look so similar but the combination of an off the shelf ESP32 module and the TMC2300 from a previous test should allow me to prove out the communication between the ESP32 and TMC2300. And the results from this should be reproduceable on the IOT reference design.
Top Comments