#include <SPIBase.h>

Inheritance diagram for SPIBase:
Collaboration diagram for SPIBase:

Public Member Functions

 SPIBase (const SpiPins &pins)
 
virtual ~SPIBase ()
 
virtual bool begin ()=0
 Initialize the SPI bus by setting SCK and MOSI to outputs, pulling SCK and MOSI low. More...
 
virtual void end ()=0
 Disable the SPI bus (leaving pin modes unchanged). More...
 
void beginTransaction (SPISettings &settings)
 Initialize the SPI bus using the defined SPISettings. More...
 
void beginTransaction (const SPISettings &settings)
 
virtual void endTransaction ()
 Stop using the SPI bus. Normally this is called after de-asserting the chip select, to allow other libraries to use the SPI bus. More...
 
void write (uint8_t data)
 
void write16 (uint16_t data)
 
void write32 (uint32_t data)
 
virtual uint8_t read8 ()
 Read one byte from SPI without setting up registers. More...
 
virtual bool loopback (bool enable)=0
 For testing, tie MISO <-> MOSI internally. More...
 
Send/receive some data

SPI transfer is based on a simultaneous send and receive: the received data is returned in receivedVal (or receivedVal16). In case of buffer transfers the received data is stored in the buffer in-place (the old data is replaced with the data received).

    receivedVal = SPI.transfer(val)
    receivedVal16 = SPI.transfer16(val16)
    SPI.transfer(buffer, size)
uint8_t transfer (uint8_t val)
 Send/receive one byte of data. More...
 
uint16_t transfer16 (uint16_t val)
 Send/receive one 16-bit word of data. More...
 
virtual uint32_t transfer32 (uint32_t val, uint8_t bits=32)
 Send/receive a word of variable size. More...
 
virtual void transfer (uint8_t *buffer, size_t size)=0
 Send/receive a variable-length block of data. More...
 

Public Attributes

SPISettings SPIDefaultSettings
 Default settings used by the SPI bus until reset by beginTransaction(SPISettings) More...
 
const SpiPinspins {mPins}
 

Protected Member Functions

virtual void prepare (SPISettings &settings)=0
 Prepare/configure with settings. More...
 
void assignDefaultPins (const SpiPins &defPins)
 Assign any default pins. More...
 

Protected Attributes

SpiPins mPins
 

Constructor & Destructor Documentation

◆ SPIBase()

SPIBase::SPIBase ( const SpiPins pins)
inline

◆ ~SPIBase()

virtual SPIBase::~SPIBase ( )
inlinevirtual

Member Function Documentation

◆ assignDefaultPins()

void SPIBase::assignDefaultPins ( const SpiPins defPins)
inlineprotected

Assign any default pins.

◆ begin()

virtual bool SPIBase::begin ( )
pure virtual

Initialize the SPI bus by setting SCK and MOSI to outputs, pulling SCK and MOSI low.

Implemented in SPISoft, and SPIClass.

◆ beginTransaction() [1/2]

void SPIBase::beginTransaction ( const SPISettings settings)
inline

◆ beginTransaction() [2/2]

void SPIBase::beginTransaction ( SPISettings settings)
inline

Initialize the SPI bus using the defined SPISettings.

◆ end()

virtual void SPIBase::end ( )
pure virtual

Disable the SPI bus (leaving pin modes unchanged).

Implemented in SPISoft, and SPIClass.

◆ endTransaction()

virtual void SPIBase::endTransaction ( )
inlinevirtual

Stop using the SPI bus. Normally this is called after de-asserting the chip select, to allow other libraries to use the SPI bus.

Reimplemented in SPISoft.

◆ loopback()

virtual bool SPIBase::loopback ( bool  enable)
pure virtual

For testing, tie MISO <-> MOSI internally.

Note: Not included in std Arduino lib

Implemented in SPISoft, and SPIClass.

◆ prepare()

virtual void SPIBase::prepare ( SPISettings settings)
protectedpure virtual

Prepare/configure with settings.

Parameters
settingsinclude frequency, byte order and SPI mode

Implemented in SPISoft, and SPIClass.

◆ read8()

virtual uint8_t SPIBase::read8 ( )
inlinevirtual

Read one byte from SPI without setting up registers.

Parameters
none
Return values
bytereceived

Used for performance tuning when doing continuous reads this method does not reset the registers, so make sure that a regular transfer(data) call was performed

Note: this method is not found on the Arduino API

USE WITH CARE !!

Reimplemented in SPIClass.

◆ transfer() [1/2]

virtual void SPIBase::transfer ( uint8_t buffer,
size_t  size 
)
pure virtual

Send/receive a variable-length block of data.

Parameters
bufferIN: The data to send; OUT: The received data
sizeNumber of bytes to transfer

Implemented in SPISoft, and SPIClass.

◆ transfer() [2/2]

uint8_t SPIBase::transfer ( uint8_t  val)
inline

Send/receive one byte of data.

Parameters
valThe byte to send
Return values
uint8_tThe received byte

◆ transfer16()

uint16_t SPIBase::transfer16 ( uint16_t  val)
inline

Send/receive one 16-bit word of data.

Parameters
valThe word to send
Return values
uint16_tThe received word

Word is transferred either MSB first (bit 15) or LSB first (bit 0) depending on the currently applied bitOrder setting.

◆ transfer32()

virtual uint32_t SPIBase::transfer32 ( uint32_t  val,
uint8_t  bits = 32 
)
inlinevirtual

Send/receive a word of variable size.

Parameters
valWord to send
bitsSize of word

Word is transferred either MSB first (bits-1) or LSB first (bit 0) depending on the currently applied bitOrder setting.

Reimplemented in SPISoft, and SPIClass.

◆ write()

void SPIBase::write ( uint8_t  data)
inline

◆ write16()

void SPIBase::write16 ( uint16_t  data)
inline

◆ write32()

void SPIBase::write32 ( uint32_t  data)
inline

Member Data Documentation

◆ mPins

SpiPins SPIBase::mPins
protected

◆ pins

const SpiPins& SPIBase::pins {mPins}

◆ SPIDefaultSettings

SPISettings SPIBase::SPIDefaultSettings

Default settings used by the SPI bus until reset by beginTransaction(SPISettings)

Note: Not included in std Arduino lib


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