Library for Trinamic TMC2209 stepper modules to drive bipolar stepper motors. Ported and adapted from https://github.com/teemuatlut/TMCStepper

Dependents:   TMC2209-Test2

Revision:
1:5ba0c258c4ed
Parent:
0:f4343071c8b1
diff -r f4343071c8b1 -r 5ba0c258c4ed TMC2208Stepper.cpp
--- a/TMC2208Stepper.cpp	Thu Mar 18 20:50:27 2021 +0000
+++ b/TMC2208Stepper.cpp	Mon Mar 22 21:35:09 2021 +0000
@@ -43,7 +43,7 @@
                         /* parity */ BufferedSerial::None,
                         /* stop bit */ 1
                     );
-            SWSerial->set_blocking(true);
+            SWSerial->set_blocking(false);  //set to non-blocking read
         }
 //        #if defined(ARDUINO_ARCH_AVR)
 //            if (RXTX_pin > 0) {
@@ -265,6 +265,10 @@
 //    uint32_t ms = millis();
     uint32_t sync_target = (static_cast<uint32_t>(datagram[0])<<16) | 0xFF00 | datagram[2];
     uint32_t sync = 0;
+    
+    // 64-bit time doesn't wrap for half a billion years, at least
+    uint64_t start_ms, now;
+    start_ms = Kernel::get_ms_count();
 
 
     do {
@@ -276,6 +280,10 @@
         }
         if (!timeout) return 0;
 */
+        // 64-bit time doesn't wrap for half a billion years, at least
+        now = Kernel::get_ms_count();
+        if (now - start_ms > timeout) return 0;
+        
         int16_t res = serial_read();
         if (res < 0) continue;
 
@@ -288,7 +296,9 @@
     uint64_t out = sync;
  //   ms = millis();
  //   timeout = this->abort_window;
-
+    
+    start_ms = Kernel::get_ms_count();
+    
     for(uint8_t i=0; i<5;) {
 /*        uint32_t ms2 = millis();
         if (ms2 != ms) {
@@ -298,6 +308,9 @@
         }
         if (!timeout) return 0;
 */
+        now = Kernel::get_ms_count();
+        if (now - start_ms > timeout) return 0;
+        
         int16_t res = serial_read();
         if (res < 0) continue;