David Rimer / RadioHead-148
Embed: (wiki syntax)

« Back to documentation index

RHHardwareSPI Class Reference

RHHardwareSPI Class Reference

Encapsulate a hardware SPI bus interface. More...

#include <RHHardwareSPI.h>

Inherits RHGenericSPI.

Public Types

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

Public Member Functions

 RHHardwareSPI (Frequency frequency=Frequency1MHz, BitOrder bitOrder=BitOrderMSBFirst, DataMode dataMode=DataMode0)
 Constructor Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on your processor platform.
uint8_t transfer (uint8_t data)
 Transfer a single octet to and from the SPI interface.
void attachInterrupt ()
 Enable SPI interrupts This can be used in an SPI slave to indicate when an SPI message has been received It will cause the SPI_STC_vect interrupt vectr to be executed.
void detachInterrupt ()
 Disable SPI interrupts This can be used to diable the SPI interrupt in slaves where that is supported.
void begin ()
 Initialise the SPI library Call this after configuring the SPI interface and before using it to transfer data.
void end ()
 Disables the SPI bus (leaving pin modes unchanged).
uint8_t transfer (uint8_t data)
 Transfer a single octet to and from the SPI interface.
void begin ()
 Initialise the SPI library.
void end ()
 Disables the SPI bus (leaving pin modes unchanged).
virtual void setBitOrder (BitOrder bitOrder)
 Sets the bit order the SPI interface will use Sets the order of the bits shifted out of and into the SPI bus, either LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).
virtual void setDataMode (DataMode dataMode)
 Sets the SPI data mode: that is, clock polarity and phase.
virtual void setFrequency (Frequency frequency)
 Sets the SPI clock divider relative to the system clock.

Protected Attributes

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 hardware SPI bus interface.

This concrete subclass of GenericSPIClass encapsulates the standard Arduino hardware and other hardware SPI interfaces.

Definition at line 18 of file RHHardwareSPI.h.


Member Enumeration Documentation

enum BitOrder [inherited]

Defines constants for different SPI endianness.

Defines constants for different SPI endianness that can be passed to setBitOrder() We need to define these in a device and platform independent way, because the SPI implementation is different on each platform.

Enumerator:
BitOrderMSBFirst 

SPI MSB first.

BitOrderLSBFirst 

SPI LSB first.

Definition at line 70 of file RHGenericSPI.h.

enum DataMode [inherited]

Defines constants for different SPI modes.

Defines constants for different SPI modes that can be passed to the constructor or setMode() We need to define these in a device and platform independent way, because the SPI implementation is different on each platform.

Enumerator:
DataMode0 

SPI Mode 0: CPOL = 0, CPHA = 0.

DataMode1 

SPI Mode 1: CPOL = 0, CPHA = 1.

DataMode2 

SPI Mode 2: CPOL = 1, CPHA = 0.

DataMode3 

SPI Mode 3: CPOL = 1, CPHA = 1.

Definition at line 40 of file RHGenericSPI.h.

enum Frequency [inherited]

Defines constants for different SPI bus frequencies.

Defines constants for different SPI bus frequencies that can be passed to setFrequency(). The frequency you get may not be exactly the one according to the name. We need to define these in a device and platform independent way, because the SPI implementation is different on each platform.

Enumerator:
Frequency1MHz 

SPI bus frequency close to 1MHz.

Frequency2MHz 

SPI bus frequency close to 2MHz.

Frequency4MHz 

SPI bus frequency close to 4MHz.

Frequency8MHz 

SPI bus frequency close to 8MHz.

Frequency16MHz 

SPI bus frequency close to 16MHz.

Definition at line 55 of file RHGenericSPI.h.


Constructor & Destructor Documentation

RHHardwareSPI ( Frequency  frequency = Frequency1MHz,
BitOrder  bitOrder = BitOrderMSBFirst,
DataMode  dataMode = DataMode0 
)

Constructor Creates an instance of a hardware SPI interface, using whatever SPI hardware is available on your processor platform.

On Arduino and Uno32, uses SPI. On Maple, uses HardwareSPI.

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.
[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

Definition at line 47 of file RHHardwareSPI.cpp.


Member Function Documentation

void attachInterrupt (  ) [virtual]

Enable SPI interrupts This can be used in an SPI slave to indicate when an SPI message has been received It will cause the SPI_STC_vect interrupt vectr to be executed.

Reimplemented from RHGenericSPI.

Definition at line 65 of file RHHardwareSPI.cpp.

void begin (  ) [virtual]

Initialise the 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.

Definition at line 79 of file RHHardwareSPI.cpp.

void begin (  ) [virtual]

Initialise the SPI library.

Call this after configuring and before using the SPI library

Implements RHGenericSPI.

Definition at line 58 of file RHHardwareSPI.h.

void detachInterrupt (  ) [virtual]

Disable SPI interrupts This can be used to diable the SPI interrupt in slaves where that is supported.

Reimplemented from RHGenericSPI.

Definition at line 72 of file RHHardwareSPI.cpp.

void end (  ) [virtual]

Disables the SPI bus (leaving pin modes unchanged).

Call this after you have finished using the SPI interface

Implements RHGenericSPI.

Definition at line 59 of file RHHardwareSPI.h.

void end (  ) [virtual]

Disables the SPI bus (leaving pin modes unchanged).

Call this after you have finished using the SPI interface.

Implements RHGenericSPI.

Definition at line 326 of file RHHardwareSPI.cpp.

void setBitOrder ( BitOrder  bitOrder ) [virtual, inherited]

Sets the bit order the SPI interface will use Sets the order of the bits shifted out of and into the SPI bus, either LSBFIRST (least-significant bit first) or MSBFIRST (most-significant bit first).

Parameters:
[in]bitOrderBit order to be used: one of RHGenericSPI::BitOrder

Definition at line 17 of file RHGenericSPI.cpp.

void setDataMode ( DataMode  dataMode ) [virtual, inherited]

Sets the SPI data mode: that is, clock polarity and phase.

See the Wikipedia article on SPI for details.

Parameters:
[in]dataModeThe mode to use: one of RHGenericSPI::DataMode

Definition at line 22 of file RHGenericSPI.cpp.

void setFrequency ( Frequency  frequency ) [virtual, inherited]

Sets the SPI clock divider relative to the system clock.

On AVR based boards, the dividers available are 2, 4, 8, 16, 32, 64 or 128. The default setting is SPI_CLOCK_DIV4, which sets the SPI clock to one-quarter the frequency of the system clock (4 Mhz for the boards at 16 MHz).

Parameters:
[in]frequencyThe data rate to use: one of RHGenericSPI::Frequency

Definition at line 27 of file RHGenericSPI.cpp.

uint8_t 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.

Definition at line 53 of file RHHardwareSPI.cpp.

uint8_t 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.

Definition at line 57 of file RHHardwareSPI.h.


Field Documentation

BitOrder _bitOrder [protected, inherited]

Bit order, one of RHGenericSPI::BitOrder.

Definition at line 132 of file RHGenericSPI.h.

DataMode _dataMode [protected, inherited]

SPI bus mode, one of RHGenericSPI::DataMode.

Definition at line 135 of file RHGenericSPI.h.

Frequency _frequency [protected, inherited]

The configure SPI Bus frequency, one of RHGenericSPI::Frequency.

Definition at line 129 of file RHGenericSPI.h.