SPIClass Class Reference

Arduino SPI interface. More...

Detailed Description

Arduino SPI interface.

Warning
Wrap all SPI transfers in SPI.beginTransaction() and SPI.endTransaction()

The official Arduino SPI-API allows to use SPI transfers without having to call SPI.beginTransaction(), but discourages to do so. The RIOT API does not provide this feature, instead a call to SPI.beginTransaction() is mandatory. However, most Arduino code already does this and the remaining code should be fixed anyway.

Definition at line 103 of file spiport.hpp.

#include <spiport.hpp>

Public Member Functions

 SPIClass (spi_t spi_dev)
 Create a new SPI interface instance. More...
 
 SPIClass (uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI, uint8_t uc_pinSS, uint8_t uc_mux)
 Create a new SPI interface instance for SPI device 0. More...
 
uint8_t transfer (uint8_t data)
 Transfer a single byte of data. More...
 
uint16_t transfer16 (uint16_t data)
 Transfer two bytes of data. More...
 
void transfer (void *buf, size_t count)
 Transfer data. More...
 
void begin ()
 Doesn't do anything, for compatibility only.
 
void end ()
 Doesn't do anything, for compatibility only.
 
void beginTransaction (SPISettings settings)
 Acquires the SPI interface and applies the given settings. More...
 
void endTransaction ()
 Releases the SPI interface.
 
void setBitOrder (uint8_t order)
 Sets the bit order to the given value. More...
 
void setDataMode (uint8_t mode)
 Sets the SPI mode (clock phase and polarity) More...
 
void setClockDivider (uint8_t divider)
 Sets the SPI clock in an archaic manner. More...
 

Constructor & Destructor Documentation

◆ SPIClass() [1/2]

SPIClass::SPIClass ( spi_t  spi_dev)
explicit

Create a new SPI interface instance.

Parameters
spi_devThe RIOT SPI device to use under the hood

◆ SPIClass() [2/2]

SPIClass::SPIClass ( uint8_t  uc_pinMISO,
uint8_t  uc_pinSCK,
uint8_t  uc_pinMOSI,
uint8_t  uc_pinSS,
uint8_t  uc_mux 
)
inline

Create a new SPI interface instance for SPI device 0.

Parameters
uc_pinMISOIgnored, for compatibility only
uc_pinSCKIgnored, for compatibility only
uc_pinMOSIIgnored, for compatibility only
uc_pinSSIgnored, for compatibility only
uc_muxIgnored, for compatibility only

Definition at line 125 of file spiport.hpp.

Member Function Documentation

◆ beginTransaction()

void SPIClass::beginTransaction ( SPISettings  settings)

Acquires the SPI interface and applies the given settings.

Parameters
[in]settingsSettings to apply

◆ setBitOrder()

void SPIClass::setBitOrder ( uint8_t  order)

Sets the bit order to the given value.

Currently only most significant bit first is supported, as practically no hardware exists using lsbfirst. An assertion is triggered if lsbfirst is requested.

Deprecated:
This function is deprecated in the official Arduino API, so it is a good idea to not use it. In RIOT, this function is not yet scheduled for removal to allow using Arduino libraries using it.

◆ setClockDivider()

void SPIClass::setClockDivider ( uint8_t  divider)

Sets the SPI clock in an archaic manner.

Deprecated:
This function is deprecated in the official Arduino API, so it is a good idea to not use it. In RIOT, this function is not yet scheduled for removal to allow using Arduino libraries using it.

◆ setDataMode()

void SPIClass::setDataMode ( uint8_t  mode)

Sets the SPI mode (clock phase and polarity)

Deprecated:
This function is deprecated in the official Arduino API, so it is a good idea to not use it. In RIOT, this function is not yet scheduled for removal to allow using Arduino libraries using it.

◆ transfer() [1/2]

uint8_t SPIClass::transfer ( uint8_t  data)
inline

Transfer a single byte of data.

Parameters
[in]dataByte to send
Returns
The received byte

Definition at line 140 of file spiport.hpp.

◆ transfer() [2/2]

void SPIClass::transfer ( void *  buf,
size_t  count 
)

Transfer data.

Parameters
[in,out]bufBuffer containing the data to send, received data will be written here
[in]countNumber of bytes to send

◆ transfer16()

uint16_t SPIClass::transfer16 ( uint16_t  data)
inline

Transfer two bytes of data.

Parameters
[in]dataThe two bytes to send
Returns
The received two bytes

Arduino is sending the most significant byte first, if the SPI interface is configured to send the most significant bit first. If the least significant bit is send first, Arduino will also send the least significant byte first.

This wrapper currently only supports sending the most significant bit first over the wire, so this function will also always send the most significant byte first.

Definition at line 160 of file spiport.hpp.


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