sw SPI interface specific for the SOLID Slow control beta!!
Fork of SWSPI by
Diff: SWSPI.cpp
- Revision:
- 2:598d0028d5d2
- Parent:
- 1:02327a96a5e2
- Child:
- 3:9c5ae1507a81
diff -r 02327a96a5e2 -r 598d0028d5d2 SWSPI.cpp --- 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; }