Half Duplex Version of SWSPI
Fork of SWSPI by
Revision 2:70039cc8ba02, committed 2018-06-19
- Comitter:
- martinsimpson
- Date:
- Tue Jun 19 10:49:39 2018 +0000
- Parent:
- 1:17d758fe52f8
- Child:
- 3:d3be72ac889e
- Commit message:
- Version 2; To correct write followed by read cycle
Changed in this revision
| SWSPI_HD.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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;
}
