Software-based SPI master. More...

#include <SPISoft.h>

Inheritance diagram for SPISoft:
Collaboration diagram for SPISoft:

Public Member Functions

bool setup (SpiPins pins)
 
bool begin () override
 Initialize the SPI bus by setting SCK and MOSI to outputs, pulling SCK and MOSI low. More...
 
void end () override
 Disable the SPI bus (leaving pin modes unchanged). More...
 
void endTransaction () override
 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...
 
uint32_t transfer32 (uint32_t val, uint8_t bits=32) override
 Send/receive a word of variable size. More...
 
void transfer (uint8_t *buffer, size_t size) override
 Send/receive a variable-length block of data. More...
 
void setDelay (uint8_t delay)
 Set delay factor for the SCK signal. Impacts SPI speed. More...
 
bool loopback (bool enable) override
 For testing, tie MISO <-> MOSI internally. More...
 
uint8_t transfer (uint8_t val)
 Send/receive one byte of data. More...
 
virtual void transfer (uint8_t *buffer, size_t size)=0
 Send/receive a variable-length block of data. More...
 
Constructors
 SPISoft ()
 Default constructor uses same pins as hardware SPI. More...
 
 SPISoft (uint8_t miso, uint8_t mosi, uint8_t sck, uint8_t delay=0)
 Specify pins to use plus optional delay. More...
 
 SPISoft (const SpiPins &pins, uint8_t delay=0)
 Specify pins plus optional delay. More...
 
 SPISoft (uint8_t delay)
 Use default pins but provide a delay. More...
 
- Public Member Functions inherited from SPIBase
 SPIBase (const SpiPins &pins)
 
virtual ~SPIBase ()
 
void beginTransaction (SPISettings &settings)
 Initialize the SPI bus using the defined SPISettings. More...
 
void beginTransaction (const SPISettings &settings)
 
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...
 
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...
 

Protected Member Functions

void prepare (SPISettings &settings) override
 Prepare/configure with settings. More...
 
- Protected Member Functions inherited from SPIBase
void assignDefaultPins (const SpiPins &defPins)
 Assign any default pins. More...
 

Additional Inherited Members

- Public Attributes inherited from SPIBase
SPISettings SPIDefaultSettings
 Default settings used by the SPI bus until reset by beginTransaction(SPISettings) More...
 
const SpiPinspins {mPins}
 
- Protected Attributes inherited from SPIBase
SpiPins mPins
 

Detailed Description

Software-based SPI master.

Intended for ESP8266 due to limited I/O but will work on any architecture.

Constructor & Destructor Documentation

◆ SPISoft() [1/4]

SPISoft::SPISoft ( )

Default constructor uses same pins as hardware SPI.

◆ SPISoft() [2/4]

SPISoft::SPISoft ( uint8_t  miso,
uint8_t  mosi,
uint8_t  sck,
uint8_t  delay = 0 
)
inline

Specify pins to use plus optional delay.

Delay is ignored if code is not compiled with SPISOFT_DELAY < 0.

◆ SPISoft() [3/4]

SPISoft::SPISoft ( const SpiPins pins,
uint8_t  delay = 0 
)
inline

Specify pins plus optional delay.

◆ SPISoft() [4/4]

SPISoft::SPISoft ( uint8_t  delay)

Use default pins but provide a delay.

Member Function Documentation

◆ begin()

bool SPISoft::begin ( )
overridevirtual

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

Implements SPIBase.

◆ end()

void SPISoft::end ( )
inlineoverridevirtual

Disable the SPI bus (leaving pin modes unchanged).

Implements SPIBase.

◆ endTransaction()

void SPISoft::endTransaction ( )
overridevirtual

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

◆ loopback()

bool SPISoft::loopback ( bool  enable)
inlineoverridevirtual

For testing, tie MISO <-> MOSI internally.

Note: Not included in std Arduino lib

Implements SPIBase.

◆ prepare()

void SPISoft::prepare ( SPISettings settings)
overrideprotectedvirtual

Prepare/configure with settings.

Parameters
settingsinclude frequency, byte order and SPI mode

Implements SPIBase.

◆ setDelay()

void SPISoft::setDelay ( uint8_t  delay)
inline

Set delay factor for the SCK signal. Impacts SPI speed.

Requires code to be compiled with SPISOFT_DELAY < 0.

ESP8266 only: The delay will be automatically calculated for a requested clock speed when begin() or beginTransaction() are called. To use only the manually programmed delay, set the clock speed to zero.

◆ setup()

bool SPISoft::setup ( SpiPins  pins)
inline

◆ transfer() [1/3]

void SPISoft::transfer ( uint8_t *  buffer,
size_t  size 
)
overridevirtual

Send/receive a variable-length block of data.

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

Implements SPIBase.

◆ transfer() [2/3]

virtual void SPIBase::transfer

Send/receive a variable-length block of data.

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

◆ transfer() [3/3]

uint8_t SPIBase::transfer
inline

Send/receive one byte of data.

Parameters
valThe byte to send
Return values
uint8_tThe received byte

◆ transfer32()

uint32_t SPISoft::transfer32 ( uint32_t  val,
uint8_t  bits = 32 
)
overridevirtual

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


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