SPI
beginTransaction()
Since 0.6.1:
Reconfigures the SPI peripheral with the supplied settings (see SPISettings
documentation).
In addition to reconfiguring the SPI peripheral, beginTransaction()
also acquires the SPI peripheral lock, blocking other threads from using the selected SPI peripheral until endTransaction()
is called. See Synchronizing Access to Shared System Resources section for additional information on shared resource locks.
It is required that you use beginTransaction()
and endTransaction()
if:
- You have more than one SPI device and they have different settings (speed, bit order, or mode)
- You have more than one thread or use SPI from a Software Timer
- You want to be compatible with the Ethernet FeatherWing or support Ethernet on your B-Series SoM base board
You must not use beginTransaction()
within a SINGLE_THREADED_BLOCK
as deadlock can occur.
// SYNTAX
SPI.beginTransaction(SPISettings(4*MHZ, MSBFIRST, SPI_MODE0));
// Pre-declared SPISettings object
SPI.beginTransaction(settings);
Parameters:
settings
:SPISettings
object with chosen settings
Returns: Negative integer in case of an error.
You should set your SPI CS/SS pin between the calls to beginTransaction()
and endTransaction()
. You typically use pinResetFast()
right after beginTransaction()
and pinSetFast()
right before endTransaction()
.
Note that you must use the same SPI
object as used with SPI.begin()
so if you used SPI1.begin()
also use SPI1.beginTransaction()
.