sw SPI interface specific for the SOLID Slow control beta!!

Dependents:   sscm SPItest sscm

Fork of SWSPI by Dave Van Wagner

Files at this revision

API Documentation at this revision

Comitter:
wbeaumont
Date:
Thu Oct 02 06:21:10 2014 +0000
Parent:
1:02327a96a5e2
Child:
3:9c5ae1507a81
Commit message:
corrected write to unsigned values

Changed in this revision

SWSPI.cpp Show annotated file Show diff for this revision Revisions of this file
SWSPI.h Show annotated file Show diff for this revision Revisions of this file
--- a/SWSPI.cpp	Tue Sep 23 08:25:01 2014 +0000
+++ b/SWSPI.cpp	Thu Oct 02 06:21:10 2014 +0000
@@ -51,17 +51,18 @@
     this->freq = hz;
 }
 
-int SWSPI::write(int value)
+unsigned int  SWSPI::write(unsigned int  value)
 {
     int read = 0;
+    //printf("SPI write %08X ",value);
     //wait(1.0/freq/2);
     for (int bit = bits-1; bit >= 0; --bit)
     {
-        mosi->write(((value >> bit) & 0x01) != 0);
+        mosi->write(((value >> bit) & 0x01) == 0);
 
         if (phase == 0)
         {
-            if (miso->read())
+            if (!miso->read())
                 read |= (1 << bit);
         }
 
@@ -71,7 +72,7 @@
 
         if (phase == 1)
         {
-            if (miso->read())
+            if (!miso->read())
                 read |= (1 << bit);
         }
 
@@ -79,6 +80,7 @@
 
         //wait(1.0/freq/2);
     }
+    //printf("  SPIR reads %08X \n\r" , read);
     return read;
 }
 
--- a/SWSPI.h	Tue Sep 23 08:25:01 2014 +0000
+++ b/SWSPI.h	Thu Oct 02 06:21:10 2014 +0000
@@ -94,7 +94,7 @@
      *  @param value  data to write (see format for bit size)
      *  returns value read from device
      */
-    int write(int value);
+    unsigned int  write(unsigned int value);
 };
 
 #endif // SWSPI_H