Description

SPISettings is used to configure the SPI port for a specific SPI device. It combines three parameters (clock speed, bit order, and data mode) into a single object that is passed to SPI.beginTransaction().

SPISettings can be used directly inside SPI.beginTransaction() when all settings are constants, which results in smaller and faster code. When any setting is a variable (especially the clock speed), creating a named SPISettings object may be more efficient.

This object is part of the SPI library. See the SPI main page for more information.

Syntax

  • SPISettings(speedMaximum, dataOrder, dataMode)
  • SPISettings mySetting(speedMaximum, dataOrder, dataMode)

Parameters

  • speedMaximum: the maximum clock speed in Hz. For example, use 20000000 for a peripheral rated up to 20 MHz.
  • dataOrder: the bit order for data transfer. Allowed values: MSBFIRST, LSBFIRST.
  • dataMode: the SPI data mode. Allowed values: SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3.

Returns

Nothing.

Example Code

// Using SPISettings directly (best when all settings are constants)
SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));

// Using a named SPISettings object (best when any setting is a variable)
SPISettings mySetting(speedMaximum, MSBFIRST, SPI_MODE0);
SPI.beginTransaction(mySetting);