RadioHead
|
Encapsulate a software SPI interface. More...
#include <RHSoftwareSPI.h>
Public Member Functions | |
RHSoftwareSPI (Frequency frequency=Frequency1MHz, BitOrder bitOrder=BitOrderMSBFirst, DataMode dataMode=DataMode0) | |
uint8_t | transfer (uint8_t data) |
void | begin () |
Initialise the SPI library. | |
void | end () |
void | setPins (uint8_t miso=12, uint8_t mosi=11, uint8_t sck=13) |
Public Member Functions inherited from RHGenericSPI | |
RHGenericSPI (Frequency frequency=Frequency1MHz, BitOrder bitOrder=BitOrderMSBFirst, DataMode dataMode=DataMode0) | |
virtual void | attachInterrupt () |
virtual void | detachInterrupt () |
virtual void | setBitOrder (BitOrder bitOrder) |
virtual void | setDataMode (DataMode dataMode) |
virtual void | setFrequency (Frequency frequency) |
virtual void | beginTransaction () |
virtual void | endTransaction () |
virtual void | usingInterrupt (uint8_t interruptNumber) |
Additional Inherited Members | |
Public Types inherited from RHGenericSPI | |
enum | DataMode { DataMode0 = 0 , DataMode1 , DataMode2 , DataMode3 } |
Defines constants for different SPI modes. More... | |
enum | Frequency { Frequency1MHz = 0 , Frequency2MHz , Frequency4MHz , Frequency8MHz , Frequency16MHz } |
Defines constants for different SPI bus frequencies. More... | |
enum | BitOrder { BitOrderMSBFirst = 0 , BitOrderLSBFirst } |
Defines constants for different SPI endianness. More... | |
Protected Attributes inherited from RHGenericSPI | |
Frequency | _frequency |
The configure SPI Bus frequency, one of RHGenericSPI::Frequency. | |
BitOrder | _bitOrder |
Bit order, one of RHGenericSPI::BitOrder. | |
DataMode | _dataMode |
SPI bus mode, one of RHGenericSPI::DataMode. | |
Encapsulate a software SPI interface.
This concrete subclass of RHGenericSPI enapsulates a bit-banged software SPI interface. Caution: this software SPI interface will be much slower than hardware SPI on most platforms.
SPI transactions are not supported, and associated functions do nothing.
Usage varies slightly depending on what driver you are using.
For RF22, for example:
RHSoftwareSPI::RHSoftwareSPI | ( | Frequency | frequency = Frequency1MHz , |
BitOrder | bitOrder = BitOrderMSBFirst , |
||
DataMode | dataMode = DataMode0 |
||
) |
Constructor Creates an instance of a bit-banged software SPI interface. Sets the SPI pins to the defaults of MISO = 12, MOSI = 11, SCK = 13. If you need other assigments, call setPins() before calling manager.init() or driver.init().
[in] | frequency | One of RHGenericSPI::Frequency to select the SPI bus frequency. The frequency is mapped to the closest available bus frequency on the platform. CAUTION: the achieved frequency will almost certainly be very much slower on most platforms. eg on Arduino Uno, the the clock rate is likely to be at best around 46kHz. |
[in] | bitOrder | Select the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or RHGenericSPI::BitOrderLSBFirst. |
[in] | dataMode | Selects the SPI bus data mode. One of RHGenericSPI::DataMode |
References setPins().
|
virtual |
Initialise the SPI library.
Initialise the software SPI library Call this after configuring the SPI interface and before using it to transfer data. Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
Implements RHGenericSPI.
References RHGenericSPI::_dataMode, RHGenericSPI::_frequency, RHGenericSPI::DataMode0, RHGenericSPI::DataMode1, RHGenericSPI::DataMode2, RHGenericSPI::Frequency16MHz, RHGenericSPI::Frequency1MHz, RHGenericSPI::Frequency2MHz, RHGenericSPI::Frequency4MHz, and RHGenericSPI::Frequency8MHz.
|
virtual |
Disables the SPI bus usually, in this case there is no hardware controller to disable.
Implements RHGenericSPI.
void RHSoftwareSPI::setPins | ( | uint8_t | miso = 12 , |
uint8_t | mosi = 11 , |
||
uint8_t | sck = 13 |
||
) |
Sets the pins used by this SoftwareSPIClass instance. The defaults are: MISO = 12, MOSI = 11, SCK = 13.
[in] | miso | master in slave out pin used |
[in] | mosi | master out slave in pin used |
[in] | sck | clock pin used |
Sets the pins used by this SoftwareSPIClass instance.
[in] | miso | master in slave out pin used |
[in] | mosi | master out slave in pin used |
[in] | sck | clock pin used |
Referenced by RHSoftwareSPI().
|
virtual |
Transfer a single octet to and from the SPI interface
[in] | data | The octet to send |
Implements RHGenericSPI.
References RHGenericSPI::_bitOrder, and RHGenericSPI::BitOrderMSBFirst.