RadioHead
Public Member Functions | List of all members
RHSoftwareSPI Class Reference

Encapsulate a software SPI interface. More...

#include <RHSoftwareSPI.h>

Inheritance diagram for RHSoftwareSPI:
RHGenericSPI

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. More...
 
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)
 

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.
 

Detailed Description

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.

Usage

Usage varies slightly depending on what driver you are using.

For RF22, for example:

#include <RHSoftwareSPI.h>
RHSoftwareSPI spi;
RH_RF22 driver(SS, 2, spi);
RHReliableDatagram(driver, CLIENT_ADDRESS);
void setup()
{
spi.setPins(6, 5, 7); // Or whatever SPI pins you need
....
}

Constructor & Destructor Documentation

◆ RHSoftwareSPI()

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().

Parameters
[in]frequencyOne 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]bitOrderSelect the SPI bus bit order, one of RHGenericSPI::BitOrderMSBFirst or RHGenericSPI::BitOrderLSBFirst.
[in]dataModeSelects the SPI bus data mode. One of RHGenericSPI::DataMode

References setPins().

Member Function Documentation

◆ begin()

void RHSoftwareSPI::begin ( )
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.

◆ end()

void RHSoftwareSPI::end ( )
virtual

Disables the SPI bus usually, in this case there is no hardware controller to disable.

Implements RHGenericSPI.

◆ setPins()

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.

Parameters
[in]misomaster in slave out pin used
[in]mosimaster out slave in pin used
[in]sckclock pin used

Sets the pins used by this SoftwareSPIClass instance.

Parameters
[in]misomaster in slave out pin used
[in]mosimaster out slave in pin used
[in]sckclock pin used

Referenced by RHSoftwareSPI().

◆ transfer()

uint8_t RHSoftwareSPI::transfer ( uint8_t  data)
virtual

Transfer a single octet to and from the SPI interface

Parameters
[in]dataThe octet to send
Returns
The octet read from SPI while the data octet was sent.

Implements RHGenericSPI.

References RHGenericSPI::BitOrderMSBFirst.


The documentation for this class was generated from the following files: