Half Duplex Version of SWSPI
Fork of SWSPI by
Diff: SWSPI_HD.cpp
- Revision:
- 2:70039cc8ba02
- Parent:
- 1:17d758fe52f8
- Child:
- 3:d3be72ac889e
diff -r 17d758fe52f8 -r 70039cc8ba02 SWSPI_HD.cpp --- a/SWSPI_HD.cpp Tue Jun 19 09:55:18 2018 +0000 +++ b/SWSPI_HD.cpp Tue Jun 19 10:49:39 2018 +0000 @@ -54,25 +54,31 @@ int SWSPI_HD::write(int value) { int read = 0; + + //Write Out + dio->output();// set as an OUTPUT + for (int bit = bits-1; bit >= 0; --bit) { dio->output();// set as an OUTPUT dio->write(((value >> bit) & 0x01) != 0); - dio->input();// set as an INPUT + sclk->write(!polarity); + wait(1.0/freq/2); + } + + //Read In + dio->input();// set as an INPUT + + for (int bit = bits-1; bit >= 0; --bit) + { if (phase == 0) { - if (dio->read()) // was miso read |= (1 << bit); } - - sclk->write(!polarity); - - wait(1.0/freq/2); - if (phase == 1) { if (dio->read()) // was miso @@ -83,7 +89,6 @@ wait(1.0/freq/2); } - return read; }