Developer World
Spresense Arduino Library v3.2.0-77d75a4
SPIClass Class Reference

SPI controller. More...

#include <SPI.h>

Public Member Functions

 SPIClass (int port)
 Create SPIClass object. More...
 
void begin (void)
 Initialize the SPI library.
 
void end (void)
 Disable the SPI bus.
 
void beginTransaction (SPISettings settings)
 Before using SPI.transfer() or asserting chip select pins, this function is used to gain exclusive access to the SPI bus and configure the correct settings. More...
 
void endTransaction (void)
 After performing a group of transfers and releasing the chip select signal, this function allows others to access the SPI bus.
 
void setBitOrder (uint8_t bitOrder)
 This function is deprecated. New applications should use beginTransaction() to configure SPI settings. More...
 
void setDataMode (uint8_t dataMode)
 This function is deprecated. New applications should use beginTransaction() to configure SPI settings. More...
 
void setClockDivider (uint8_t clockDiv)
 This function is deprecated. New applications should use beginTransaction() to configure SPI settings. More...
 
void usingInterrupt (uint8_t interruptNumber)
 Register interrupt with the SPI library. More...
 
void notUsingInterrupt (uint8_t interruptNumber)
 Disable interrupt with the SPI library. More...
 
uint8_t transfer (uint8_t data)
 Write 8-bit data to the SPI bus and also receive 8-bit data. More...
 
uint16_t transfer16 (uint16_t data)
 Write 16-bit data to the SPI bus and also receive 16-bit data. More...
 
void transfer (void *buf, size_t count)
 Write data to the SPI bus and also receive data. More...
 
void transfer16 (void *buf, size_t count)
 Write 16-bit data to the SPI bus and also receive data. More...
 
void send (void *buf, size_t count)
 Write buffer to the SPI bus (only write transfer) More...
 
void send16 (void *buf, size_t count)
 Write 16-bit buffer the SPI bus (only write transfer) More...
 
void selectCS (int cs)
 Select chip select number (only for SPI3) More...
 
void enableCS ()
 Enable chip select by software (only for SPI3) More...
 
void disableCS ()
 Disable chip select by software (only for SPI3) More...
 

Detailed Description

SPI controller.

You can control SPI comunication by operating SPIClass objects instantiated in your app.

Constructor & Destructor Documentation

◆ SPIClass()

SPIClass::SPIClass ( int  port)

Create SPIClass object.

Parameters
[in]portThe default port is 4. You can control SPI4 using object SPI
e.g. SPI.begin();
SPI5 is also supported. You can control SPI5 using object SPI5
e.g. SPI5.begin();

Member Function Documentation

◆ beginTransaction()

void SPIClass::beginTransaction ( SPISettings  settings)

Before using SPI.transfer() or asserting chip select pins, this function is used to gain exclusive access to the SPI bus and configure the correct settings.

Parameters
[in]settingsSPISettings object

◆ setBitOrder()

void SPIClass::setBitOrder ( uint8_t  bitOrder)

This function is deprecated. New applications should use beginTransaction() to configure SPI settings.

Parameters
[in]bitOrderBit order

◆ setDataMode()

void SPIClass::setDataMode ( uint8_t  dataMode)

This function is deprecated. New applications should use beginTransaction() to configure SPI settings.

Parameters
[in]dataModeSPI mode

◆ setClockDivider()

void SPIClass::setClockDivider ( uint8_t  clockDiv)

This function is deprecated. New applications should use beginTransaction() to configure SPI settings.

Parameters
[in]clockDivClock divider

◆ usingInterrupt()

void SPIClass::usingInterrupt ( uint8_t  interruptNumber)

Register interrupt with the SPI library.

If SPI is used from within an interrupt, this function registers that interrupt with the SPI library, so beginTransaction() can prevent conflicts. The input interruptNumber is the number used with attachInterrupt. If SPI is used from a different interrupt (eg, a timer), interruptNumber should be 255.

Note
The usingInterrupt and notUsingInterrupt functions should not to be called from ISR context or inside a transaction.
See also
For details see:
https://github.com/arduino/Arduino/pull/2381
https://github.com/arduino/Arduino/pull/2449
Parameters
[in]interruptNumberInterrupt number

◆ notUsingInterrupt()

void SPIClass::notUsingInterrupt ( uint8_t  interruptNumber)

Disable interrupt with the SPI library.

Note
The usingInterrupt and notUsingInterrupt functions should not to be called from ISR context or inside a transaction.
See also
For details see:
https://github.com/arduino/Arduino/pull/2381
https://github.com/arduino/Arduino/pull/2449
Parameters
[in]interruptNumberInterrupt number

◆ transfer() [1/2]

uint8_t SPIClass::transfer ( uint8_t  data)

Write 8-bit data to the SPI bus and also receive 8-bit data.

Parameters
[in]data8-bit data to send
Returns
Received 8-bit data

◆ transfer16() [1/2]

uint16_t SPIClass::transfer16 ( uint16_t  data)

Write 16-bit data to the SPI bus and also receive 16-bit data.

Parameters
[in]data16-bit data to send
Returns
Received 16-bit data

◆ transfer() [2/2]

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

Write data to the SPI bus and also receive data.

Parameters
[in,out]bufBuffer to send and receive
[in]countThe number of bytes to transmit

◆ transfer16() [2/2]

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

Write 16-bit data to the SPI bus and also receive data.

Parameters
[in,out]bufBuffer to send and receive
[in]countThe number of 16-bit data to transmit

◆ send()

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

Write buffer to the SPI bus (only write transfer)

Note
This supports only Tx transfer. There is no Rx received data. It assumes that this is used for LCD display.
Parameters
[in]bufBuffer to send
[in]countThe number of bytes to transmit

◆ send16()

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

Write 16-bit buffer the SPI bus (only write transfer)

Note
This supports only Tx transfer. There is no Rx received data. It assumes that this is used for LCD display.
Parameters
[in]bufBuffer to send
[in]countThe number of 16-bit data to transmit

◆ selectCS()

void SPIClass::selectCS ( int  cs)

Select chip select number (only for SPI3)

Parameters
[in]cschip select number When SPI3_CS0_X is used, set cs to 0 (default). When SPI3_CS1_X is used, set cs to 1.
Note
This is a function supported only for SPI3.

◆ enableCS()

void SPIClass::enableCS ( )

Enable chip select by software (only for SPI3)

Note
This is a function supported only for SPI3.

◆ disableCS()

void SPIClass::disableCS ( )

Disable chip select by software (only for SPI3)

Note
This is a function supported only for SPI3.

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