STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
SPIClass Class Reference

SPI controller or peripheral instance. More...

#include <SPI.h>

Inheritance diagram for SPIClass:

Public Member Functions

 SPIClass (pin_size_t mosi=MOSI, pin_size_t miso=MISO, pin_size_t sclk=SCK, pin_size_t ssel=PNUM_NOT_DEFINED)
 Construct an SPI instance using the given pins.
 
void setMISO (pin_size_t miso)
 Set the MISO pin.
 
void setMOSI (pin_size_t mosi)
 Set the MOSI pin.
 
void setSCLK (pin_size_t sclk)
 Set the SCLK pin.
 
void setSSEL (pin_size_t ssel)
 Set the SSEL pin.
 
void setMISO (PinName miso)
 Set the MISO pin.
 
void setMOSI (PinName mosi)
 Set the MOSI pin.
 
void setSCLK (PinName sclk)
 Set the SCLK pin.
 
void setSSEL (PinName ssel)
 Set the SSEL pin.
 
void begin (SPIBusMode busMode)
 Initialize the SPI instance with the default parameters: 4 MHz, MSBFIRST, SPI_MODE0.
 
void begin () override
 Initialize the SPI instance as controller (default bus mode) with the default parameters.
 
void end (void) override
 Deinitialize the SPI instance and stop it.
 
void beginTransaction (SPISettings settings) override
 Configure the SPI instance with the given settings, when the default parameters of begin() are not suitable.
 
void endTransaction (void) override
 End the transaction started with beginTransaction().
 
uint8_t transfer (uint8_t data, bool skipReceive)
 Transfer one byte on the SPI bus.
 
uint8_t transfer (uint8_t data) override
 Transfer one byte on the SPI bus and receive data.
 
uint16_t transfer16 (uint16_t data, bool skipReceive)
 Transfer two bytes on the SPI bus in 16-bit format.
 
uint16_t transfer16 (uint16_t data) override
 Transfer two bytes on the SPI bus in 16-bit format and receive data.
 
void transfer (void *buf, size_t count, bool skipReceive)
 Transfer several bytes using one buffer to send and receive.
 
void transfer (void *buf, size_t count) override
 Transfer several bytes using one buffer to send and receive data.
 
void transfer (const void *tx_buf, void *rx_buf, size_t count)
 Transfer several bytes using one constant Tx buffer and one Rx buffer.
 
void usingInterrupt (int interruptNumber) override
 Not implemented.
 
void notUsingInterrupt (int interruptNumber) override
 Not implemented.
 
void attachInterrupt (void) override
 Not implemented.
 
void detachInterrupt (void) override
 Not implemented.
 
SPI_HandleTypeDef * getHandle (void)
 Get the SPI handle to mix the Arduino API and the STM32Cube HAL API (e.g.
 
void attachSlaveInterrupt (uint8_t pin, voidFuncPtr callback)
 Attach a callback on the falling edge of a pin.
 
void detachSlaveInterrupt (uint8_t pin)
 Detach the callback attached with attachSlaveInterrupt().
 

Protected Attributes

spi_t _spi
 SPI instance data.
 

Detailed Description

SPI controller or peripheral instance.

The default instance is SPI.

Constructor & Destructor Documentation

◆ SPIClass()

SPIClass::SPIClass ( pin_size_t  mosi = MOSI,
pin_size_t  miso = MISO,
pin_size_t  sclk = SCK,
pin_size_t  ssel = PNUM_NOT_DEFINED 
)

Construct an SPI instance using the given pins.

Default values are the pins of the default SPI peripheral defined in the variant. All pins must be attached to the same SPI peripheral, see the datasheet of the microcontroller.

Parameters
mosiSPI MOSI pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).
misoSPI MISO pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).
sclkSPI clock pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).
sselOptional SPI SSEL pin, must be a hardware CS pin managed by the SPI peripheral itself (see PinMap_SPI_SSEL[] in the PeripheralPins.c file of the board and the datasheet of the microcontroller). If set, no other CS pin can be used and no CS pin must be passed to any function of the class. Default: not defined (no hardware SSEL).
Note
To create another SPI instance attached to another SPI peripheral, give its pins as parameters.

Member Function Documentation

◆ attachInterrupt()

void SPIClass::attachInterrupt ( void  )
override

Not implemented.

Kept for compatibility.

◆ attachSlaveInterrupt()

void SPIClass::attachSlaveInterrupt ( uint8_t  pin,
voidFuncPtr  callback 
)
inline

Attach a callback on the falling edge of a pin.

Dedicated to SPI slave (chip select detection).

Parameters
pinPin number.
callbackFunction called on the falling edge.

◆ begin()

void SPIClass::begin ( SPIBusMode  busMode)

Initialize the SPI instance with the default parameters: 4 MHz, MSBFIRST, SPI_MODE0.

Parameters
busModeBus mode: SPI_CONTROLLER or SPI_PERIPHERAL.

◆ beginTransaction()

void SPIClass::beginTransaction ( SPISettings  settings)
override

Configure the SPI instance with the given settings, when the default parameters of begin() are not suitable.

Parameters
settingsSPI settings (clock speed, bit order, data mode, bus mode).

◆ detachInterrupt()

void SPIClass::detachInterrupt ( void  )
override

Not implemented.

Kept for compatibility.

◆ detachSlaveInterrupt()

void SPIClass::detachSlaveInterrupt ( uint8_t  pin)
inline

Detach the callback attached with attachSlaveInterrupt().

Parameters
pinPin number.

◆ getHandle()

SPI_HandleTypeDef * SPIClass::getHandle ( void  )
inline

Get the SPI handle to mix the Arduino API and the STM32Cube HAL API (e.g.

DMA).

Warning
Use at your own risk.
Returns
Pointer to the SPI handle.

◆ notUsingInterrupt()

void SPIClass::notUsingInterrupt ( int  interruptNumber)
override

Not implemented.

Kept for compatibility.

Parameters
interruptNumberUnused.

◆ setMISO() [1/2]

void SPIClass::setMISO ( pin_size_t  miso)
inline

Set the MISO pin.

Must be called before begin().

Parameters
misoMISO pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).

◆ setMISO() [2/2]

void SPIClass::setMISO ( PinName  miso)
inline

Set the MISO pin.

Must be called before begin().

Parameters
misoMISO PinName.

◆ setMOSI() [1/2]

void SPIClass::setMOSI ( pin_size_t  mosi)
inline

Set the MOSI pin.

Must be called before begin().

Parameters
mosiMOSI pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).

◆ setMOSI() [2/2]

void SPIClass::setMOSI ( PinName  mosi)
inline

Set the MOSI pin.

Must be called before begin().

Parameters
mosiMOSI PinName.

◆ setSCLK() [1/2]

void SPIClass::setSCLK ( pin_size_t  sclk)
inline

Set the SCLK pin.

Must be called before begin().

Parameters
sclkSCLK pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).

◆ setSCLK() [2/2]

void SPIClass::setSCLK ( PinName  sclk)
inline

Set the SCLK pin.

Must be called before begin().

Parameters
sclkSCLK PinName.

◆ setSSEL() [1/2]

void SPIClass::setSSEL ( pin_size_t  ssel)
inline

Set the SSEL pin.

Must be called before begin().

Parameters
sselSSEL pin. Accepted format: number, Arduino format (Dx) or ST format (Pxy).

◆ setSSEL() [2/2]

void SPIClass::setSSEL ( PinName  ssel)
inline

Set the SSEL pin.

Must be called before begin().

Parameters
sselSSEL PinName.

◆ transfer() [1/5]

void SPIClass::transfer ( const void *  tx_buf,
void *  rx_buf,
size_t  count 
)

Transfer several bytes using one constant Tx buffer and one Rx buffer.

begin() or beginTransaction() must be called at least once before. Expands the SPI API, see https://github.com/arduino/ArduinoCore-API/discussions/189

Parameters
tx_bufArray of Tx bytes filled by the user before the transfer. If NULL, dummy 0xFF bytes are clocked out.
rx_bufArray of Rx bytes filled by the peripheral during the transfer. If NULL, the received data is discarded.
countNumber of bytes to send/receive.

◆ transfer() [2/5]

uint8_t SPIClass::transfer ( uint8_t  data)
inlineoverride

Transfer one byte on the SPI bus and receive data.

begin() or beginTransaction() must be called at least once before.

Parameters
dataByte to send.
Returns
Byte received from the peripheral.

◆ transfer() [3/5]

uint8_t SPIClass::transfer ( uint8_t  data,
bool  skipReceive 
)

Transfer one byte on the SPI bus.

begin() or beginTransaction() must be called at least once before.

Parameters
dataByte to send.
skipReceivetrue to skip receiving data (SPI_TRANSMITONLY), false to receive (SPI_TRANSMITRECEIVE).
Returns
Byte received from the peripheral.

◆ transfer() [4/5]

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

Transfer several bytes using one buffer to send and receive data.

begin() or beginTransaction() must be called at least once before.

Parameters
bufPointer to the bytes to send. The bytes received are copied in this buffer.
countNumber of bytes to send/receive.

◆ transfer() [5/5]

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

Transfer several bytes using one buffer to send and receive.

begin() or beginTransaction() must be called at least once before.

Parameters
bufPointer to the bytes to send. The bytes received are copied in this buffer.
countNumber of bytes to send/receive.
skipReceivetrue to skip receiving data (SPI_TRANSMITONLY), false to receive (SPI_TRANSMITRECEIVE).

◆ transfer16() [1/2]

uint16_t SPIClass::transfer16 ( uint16_t  data)
inlineoverride

Transfer two bytes on the SPI bus in 16-bit format and receive data.

begin() or beginTransaction() must be called at least once before.

Parameters
dataBytes to send.
Returns
Bytes received from the peripheral in 16-bit format.

◆ transfer16() [2/2]

uint16_t SPIClass::transfer16 ( uint16_t  data,
bool  skipReceive 
)

Transfer two bytes on the SPI bus in 16-bit format.

begin() or beginTransaction() must be called at least once before.

Parameters
dataBytes to send.
skipReceivetrue to skip receiving data (SPI_TRANSMITONLY), false to receive (SPI_TRANSMITRECEIVE).
Returns
Bytes received from the peripheral in 16-bit format.

◆ usingInterrupt()

void SPIClass::usingInterrupt ( int  interruptNumber)
override

Not implemented.

Kept for compatibility.

Parameters
interruptNumberUnused.

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