Jack Hansdampf / SoftwareI2C
Revision:
4:07b9f0e0424c
Parent:
2:8670e78c4b63
diff -r e15fb8277f9b -r 07b9f0e0424c SoftwareI2C.h
--- a/SoftwareI2C.h	Wed Mar 04 18:29:47 2020 +0000
+++ b/SoftwareI2C.h	Tue Apr 14 12:49:03 2020 +0000
@@ -44,7 +44,7 @@
         
         _sda = 1;
         _scl = 0;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
 
         for ( int n = 0; n <= 3; ++n ) {
             stop();
@@ -52,35 +52,44 @@
     }
 
 private:
+    void warte(int zeit)
+    {
+     for (int i=0;i<zeit*5;i++)
+     {
+      asm(
+        "nop\n\t"
+      );   
+     }   
+    }
     inline void start() {
         _sda.output();
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _scl = 1;
         _sda = 1;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _sda = 0;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _scl = 0;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
     }
 
     inline void stop() {
         _sda.output();
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _sda = 0;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _scl = 1;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _sda = 1;
     }
 
     inline void putByte(uint8_t byte) {
         _sda.output();
         for ( int n = 8; n > 0; --n) {
-            wait_us(_frequency_delay);
+            warte(_frequency_delay);
             _sda = byte & (1 << (n-1));
             _scl = 1;
-            wait_us(_frequency_delay);
+            warte(_frequency_delay);
             _scl = 0;
         }
         _sda = 1;
@@ -92,15 +101,15 @@
         _sda.input();          //release the data line
         _sda.mode(OpenDrain);
         
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
 
         for ( int n = 8; n > 0; --n ) {
             _scl=1;            //set clock high
-            wait_us(_frequency_delay);
+            warte(_frequency_delay);
             byte |= _sda << (n-1); //read the bit
-            wait_us(_frequency_delay);
+            warte(_frequency_delay);
             _scl=0;            //set clock low
-            wait_us(_frequency_delay);
+            warte(_frequency_delay);
         }
 
         _sda.output();         //take data line back
@@ -110,10 +119,10 @@
 
     inline void giveAck() {
         _sda.output();
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _sda = 0;
         _scl = 1;
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _scl = 0;
         _sda = 1;
 
@@ -125,12 +134,12 @@
         _scl = 1;
         _sda.input();
         _sda.mode(OpenDrain);
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         _scl = 0;
 
         if(_sda != 0){return false;}
 
-        wait_us(_frequency_delay);
+        warte(_frequency_delay);
         return true;
     }