sw SPI interface specific for the SOLID Slow control beta!!
Fork of SWSPI by
Diff: SWSPI.cpp
- Revision:
- 1:02327a96a5e2
- Parent:
- 0:6a500a08c7fd
- Child:
- 2:598d0028d5d2
--- a/SWSPI.cpp Tue Feb 04 06:54:01 2014 +0000 +++ b/SWSPI.cpp Tue Sep 23 08:25:01 2014 +0000 @@ -23,27 +23,25 @@ #include <mbed.h> #include "SWSPI.h" -SWSPI::SWSPI(PinName mosi_pin, PinName miso_pin, PinName sclk_pin) +SWSPI::SWSPI(DigitalOut *mosi_pin, DigitalIn *miso_pin, DigitalOut *sclk_pin) { - mosi = new DigitalOut(mosi_pin); - miso = new DigitalIn(miso_pin); - sclk = new DigitalOut(sclk_pin); + mosi = mosi_pin; + miso = miso_pin; + sclk = sclk_pin; format(8); frequency(); } SWSPI::~SWSPI() { - delete mosi; - delete miso; - delete sclk; + } void SWSPI::format(int bits, int mode) { this->bits = bits; this->mode = mode; - polarity = (mode >> 1) & 1; + polarity = !((mode >> 1) & 1); phase = mode & 1; sclk->write(polarity); } @@ -56,6 +54,7 @@ int SWSPI::write(int value) { int read = 0; + //wait(1.0/freq/2); for (int bit = bits-1; bit >= 0; --bit) { mosi->write(((value >> bit) & 0x01) != 0); @@ -68,7 +67,7 @@ sclk->write(!polarity); - wait(1.0/freq/2); + //wait(1.0/freq/2); if (phase == 1) { @@ -78,9 +77,8 @@ sclk->write(polarity); - wait(1.0/freq/2); + //wait(1.0/freq/2); } - return read; }