8 #include "GenericSPI.h"
37 if (_bitOrder == MSBFIRST)
48 for (uint8_t count=0; count<8; count++)
63 digitalWrite(_mosi, writeData);
64 digitalWrite(_sck, ~_clockPolarity);
68 readData = digitalRead(_miso);
69 digitalWrite(_sck, _clockPolarity);
75 digitalWrite(_mosi, writeData);
76 digitalWrite(_sck, _clockPolarity);
80 readData = digitalRead(_miso);
81 digitalWrite(_sck, ~_clockPolarity);
86 if (_bitOrder == MSBFIRST)
89 builtReturn |= (readData << (7 - count));
94 builtReturn |= (readData << count);
98 digitalWrite(_sck, _clockPolarity);
112 _clockPolarity = LOW;
114 _bitOrder = MSBFIRST;
115 _delayCounts = SPI_CLOCK_DIV4;
126 void setPins(uint8_t miso, uint8_t mosi, uint8_t sck)
132 pinMode(_miso, INPUT);
133 pinMode(_mosi, OUTPUT);
134 pinMode(_sck, OUTPUT);
135 digitalWrite(_sck, _clockPolarity);
144 _bitOrder = bitOrder;
152 if (mode == SPI_MODE0 ||
155 _clockPolarity = LOW;
162 if (mode == SPI_MODE0 ||
172 digitalWrite(_sck, _clockPolarity);
190 for (
volatile uint8_t count; count<_delayCounts; count++)
192 __asm__ __volatile__ (
"nop");
202 uint8_t _delayCounts;
203 uint8_t _clockPolarity;
void setDataMode(uint8_t mode)
Definition: SoftwareSPI.h:150
void setPins(uint8_t miso, uint8_t mosi, uint8_t sck)
Definition: SoftwareSPI.h:126
void begin()
Initialise the SPI library.
Definition: SoftwareSPI.h:110
void setClockDivider(uint8_t rate)
Definition: SoftwareSPI.h:180
Encapsulate a software SPI interface.
Definition: SoftwareSPI.h:22
uint8_t transfer(uint8_t data)
Definition: SoftwareSPI.h:30
void detachInterrupt()
Not implemented.
Definition: SoftwareSPI.h:107
void setBitOrder(uint8_t bitOrder)
Definition: SoftwareSPI.h:142
Base class for SPI interfaces.
Definition: GenericSPI.h:28
void end()
there is no hardware controller to disable.
Definition: SoftwareSPI.h:120
void attachInterrupt()
Not implemented.
Definition: SoftwareSPI.h:104