I've done lots of searching on this, including this forum, ChatGPT, reading the TMC2209 data sheet and I'm still having an issue. It's not critical because I have the TMC2209 working with UART to set driver settings and my motor is running fine, but I have the DIAG pin hooked up in my design and I can't get StallGuard to trigger either the DIAG pin or to give me any reading at all via:
driver.SG_RESULT()
From what I have gathered, there is some magical combination of driver settings that enables StallGuard. So far, I have not been able to conjure up the correct recipe. I will post what I have, but I'm wondering if anyone has a working config for this that I could try. Here's what I've got so far (which works to run my motor). To be clear, I've tried it with and without the commented out code and I know I have some duplicative stuff in there as well.
//Start Motor Driver
digitalWrite(ENABLE_PIN, LOW); // Enable the driver
driver.begin();
Serial.println("Stepper Driver Enabled");
Serial.println(F("Driver Settings:"));
driver.toff(4); // Set driver off time
driver.blank_time(24);
Serial.print(F("Driver Blank Time: "));
Serial.println(driver.blank_time());
driver.en_spreadCycle(0);
Serial.print(F("SpreadCycle: "));
Serial.println(driver.en_spreadCycle());
// driver.pwm_autoscale(1);
// Serial.print(F("PWM Autoscale: "));
// Serial.println(driver.pwm_autoscale());
// DisableStealthChop PWM mode/ Page 25 of datasheet
// driver.TPWMTHRS(0);
driver.TCOOLTHRS(0xFFFFF); // 20bit max
driver.semin(5);
driver.semax(2);
driver.sedn(0b01);
driver.rms_current(1500); // Set RMS current to 1.5A. The value is in milliamps.
Serial.print(F("RMS current: "));
Serial.print(driver.rms_current());
Serial.println(F(" mA"));
driver.mstep_reg_select(true);
driver.microsteps(2); // 1,2,4,16,32 (1= full step, 2=1/2 step, 4=1/4 step, etc.)
Serial.print(F("Microstep Config Setting: "));
Serial.println(driver.microsteps());
driver.semin(0);
driver.TCOOLTHRS(50);
Serial.print(F("CoolStep: "));
Serial.println(driver.semin());
driver.intpol(true); // Interpolate to 256 steps, smooth stepping even with 0 microsteps.
Serial.print(F("Microstep Config Actual: "));
Serial.println(driver.microsteps());
driver.SGTHRS(128); // Set StallGuard threshold. You may need to adjust the value for your setup.
Serial.print(F("StallGuard threshold: "));
Serial.println(driver.SGTHRS());
driver.pdn_disable(true); // Disable power down (required for UART)
Thanks in advance!