Testprogram for TMC2209-Library. Uses Speed-Control via VACTUAL instead of Step/Dir

Dependencies:   TMCStepper mRotaryEncoder-os

Revision:
9:babbfb61d347
Parent:
8:f44d70665051
Child:
10:376299814a3b
--- a/main.cpp	Thu Apr 22 18:11:49 2021 +0000
+++ b/main.cpp	Thu Dec 02 20:30:09 2021 +0000
@@ -96,11 +96,31 @@
     
     // disable Driver
     enn=1;
+    // wait for Hhardware to settle
+    ThisThread::sleep_for(100ms);
         
     // Initialize Stepper
     printf("connecting to TMC-Module...\r\n");
     stepper.begin();                    // UART: Init SW UART (if selected) with default baudrate
-    printf("TMC-Version: %02X\r\n",stepper.version());
+    
+    //read and check version - must be 0x21
+    uint8_t tmc_version = stepper.version();
+    printf("TMC-Version: %02X\r\n",tmc_version);
+    if (tmc_version != 0x21) {
+            printf("Wrong TMC-Version(not 0x21) or communication error!! STOPPING!!!\r\n");
+            if (stepper.CRCerror) {
+                printf("CRC-Error!!!\r\n");
+            }
+            while (1) {
+                ledCW = 1;
+                ledCCW = 0;
+                ThisThread::sleep_for(50ms);
+                ledCW = 0;
+                ledCCW = 1;
+                ThisThread::sleep_for(50ms);
+            };
+    }
+    
     stepper.push();                     // initialize all registers??? required?
     
     stepper.toff(3);                    // Enables driver in software - 3, 5 ????
@@ -138,17 +158,18 @@
     
     // do a peep by setting vactual to a too high speed
     
-    stepper.VACTUAL(50000*MICROSTEPS);
-    ThisThread::sleep_for(1s);
+    //stepper.VACTUAL(50000*MICROSTEPS);
+    //ThisThread::sleep_for(1s);
     
     // initialize Automatic tunig (Chap 6.1)
+    printf("Start automatic tunig Chap6.1 .....");
     stepper.VACTUAL(1);
     stepper.VACTUAL(0);
     ThisThread::sleep_for(100ms);
     stepper.VACTUAL(500*MICROSTEPS);
     ThisThread::sleep_for(2s);
     stepper.VACTUAL(0);
-    
+    printf("done\r\n");
     
     diag.rise(&trigger_diag);