Adafruit Bus IO Library
Public Member Functions | List of all members
Adafruit_SPIDevice Class Reference

#include <Adafruit_SPIDevice.h>

Public Member Functions

 Adafruit_SPIDevice (int8_t cspin, uint32_t freq=1000000, BusIOBitOrder dataOrder=SPI_BITORDER_MSBFIRST, uint8_t dataMode=SPI_MODE0, SPIClass *theSPI=&SPI)
 Create an SPI device with the given CS pin and settings. More...
 
 Adafruit_SPIDevice (int8_t cspin, int8_t sck, int8_t miso, int8_t mosi, uint32_t freq=1000000, BusIOBitOrder dataOrder=SPI_BITORDER_MSBFIRST, uint8_t dataMode=SPI_MODE0)
 Create an SPI device with the given CS pin and settings. More...
 
 ~Adafruit_SPIDevice ()
 Release memory allocated in constructors.
 
bool begin (void)
 Initializes SPI bus and sets CS pin high. More...
 
bool read (uint8_t *buffer, size_t len, uint8_t sendvalue=0xFF)
 Read from SPI into a buffer from the SPI device, with transaction management. More...
 
bool write (const uint8_t *buffer, size_t len, const uint8_t *prefix_buffer=nullptr, size_t prefix_len=0)
 Write a buffer or two to the SPI device, with transaction management. More...
 
bool write_then_read (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, uint8_t sendvalue=0xFF)
 Write some data, then read some data from SPI into another buffer, with transaction management. The buffers can point to same/overlapping locations. This does not transmit-receive at the same time! More...
 
bool write_and_read (uint8_t *buffer, size_t len)
 Write some data and read some data at the same time from SPI into the same buffer, with transaction management. This is basicaly a wrapper for transfer() with CS-pin and transaction management. This /does/ transmit-receive at the same time! More...
 
uint8_t transfer (uint8_t send)
 Transfer (send/receive) one byte over hard/soft SPI, without transaction management. More...
 
void transfer (uint8_t *buffer, size_t len)
 Transfer (send/receive) a buffer over hard/soft SPI, without transaction management. More...
 
void beginTransaction (void)
 Manually begin a transaction (calls beginTransaction if hardware SPI)
 
void endTransaction (void)
 Manually end a transaction (calls endTransaction if hardware SPI)
 
void beginTransactionWithAssertingCS ()
 Write a buffer or two to the SPI device, with transaction management. More...
 
void endTransactionWithDeassertingCS ()
 Manually end a transaction (calls endTransaction if hardware SPI) with deasserting the CS pin.
 

Detailed Description

! The class which defines how we will talk to this device over SPI

Constructor & Destructor Documentation

◆ Adafruit_SPIDevice() [1/2]

Adafruit_SPIDevice::Adafruit_SPIDevice ( int8_t  cspin,
uint32_t  freq = 1000000,
BusIOBitOrder  dataOrder = SPI_BITORDER_MSBFIRST,
uint8_t  dataMode = SPI_MODE0,
SPIClass *  theSPI = &SPI 
)

Create an SPI device with the given CS pin and settings.

Parameters
cspinThe arduino pin number to use for chip select
freqThe SPI clock frequency to use, defaults to 1MHz
dataOrderThe SPI data order to use for bits within each byte, defaults to SPI_BITORDER_MSBFIRST
dataModeThe SPI mode to use, defaults to SPI_MODE0
theSPIThe SPI bus to use, defaults to &theSPI

◆ Adafruit_SPIDevice() [2/2]

Adafruit_SPIDevice::Adafruit_SPIDevice ( int8_t  cspin,
int8_t  sckpin,
int8_t  misopin,
int8_t  mosipin,
uint32_t  freq = 1000000,
BusIOBitOrder  dataOrder = SPI_BITORDER_MSBFIRST,
uint8_t  dataMode = SPI_MODE0 
)

Create an SPI device with the given CS pin and settings.

Parameters
cspinThe arduino pin number to use for chip select
sckpinThe arduino pin number to use for SCK
misopinThe arduino pin number to use for MISO, set to -1 if not used
mosipinThe arduino pin number to use for MOSI, set to -1 if not used
freqThe SPI clock frequency to use, defaults to 1MHz
dataOrderThe SPI data order to use for bits within each byte, defaults to SPI_BITORDER_MSBFIRST
dataModeThe SPI mode to use, defaults to SPI_MODE0

Member Function Documentation

◆ begin()

bool Adafruit_SPIDevice::begin ( void  )

Initializes SPI bus and sets CS pin high.

Returns
Always returns true because there's no way to test success of SPI init

◆ read()

bool Adafruit_SPIDevice::read ( uint8_t *  buffer,
size_t  len,
uint8_t  sendvalue = 0xFF 
)

Read from SPI into a buffer from the SPI device, with transaction management.

Parameters
bufferPointer to buffer of data to read into
lenNumber of bytes from buffer to read.
sendvalueThe 8-bits of data to write when doing the data read, defaults to 0xFF
Returns
Always returns true because there's no way to test success of SPI writes

◆ write()

bool Adafruit_SPIDevice::write ( const uint8_t *  buffer,
size_t  len,
const uint8_t *  prefix_buffer = nullptr,
size_t  prefix_len = 0 
)

Write a buffer or two to the SPI device, with transaction management.

Parameters
bufferPointer to buffer of data to write
lenNumber of bytes from buffer to write
prefix_bufferPointer to optional array of data to write before buffer.
prefix_lenNumber of bytes from prefix buffer to write
Returns
Always returns true because there's no way to test success of SPI writes

◆ write_then_read()

bool Adafruit_SPIDevice::write_then_read ( const uint8_t *  write_buffer,
size_t  write_len,
uint8_t *  read_buffer,
size_t  read_len,
uint8_t  sendvalue = 0xFF 
)

Write some data, then read some data from SPI into another buffer, with transaction management. The buffers can point to same/overlapping locations. This does not transmit-receive at the same time!

Parameters
write_bufferPointer to buffer of data to write from
write_lenNumber of bytes from buffer to write.
read_bufferPointer to buffer of data to read into.
read_lenNumber of bytes from buffer to read.
sendvalueThe 8-bits of data to write when doing the data read, defaults to 0xFF
Returns
Always returns true because there's no way to test success of SPI writes

◆ write_and_read()

bool Adafruit_SPIDevice::write_and_read ( uint8_t *  buffer,
size_t  len 
)

Write some data and read some data at the same time from SPI into the same buffer, with transaction management. This is basicaly a wrapper for transfer() with CS-pin and transaction management. This /does/ transmit-receive at the same time!

Parameters
bufferPointer to buffer of data to write/read to/from
lenNumber of bytes from buffer to write/read.
Returns
Always returns true because there's no way to test success of SPI writes

◆ transfer() [1/2]

uint8_t Adafruit_SPIDevice::transfer ( uint8_t  send)

Transfer (send/receive) one byte over hard/soft SPI, without transaction management.

Parameters
sendThe byte to send
Returns
The byte received while transmitting

◆ transfer() [2/2]

void Adafruit_SPIDevice::transfer ( uint8_t *  buffer,
size_t  len 
)

Transfer (send/receive) a buffer over hard/soft SPI, without transaction management.

Parameters
bufferThe buffer to send and receive at the same time
lenThe number of bytes to transfer

◆ beginTransactionWithAssertingCS()

void Adafruit_SPIDevice::beginTransactionWithAssertingCS ( )

Write a buffer or two to the SPI device, with transaction management.

Manually begin a transaction (calls beginTransaction if hardware SPI) with asserting the CS pin


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