The Embedded Insights examples use the Arduino SPI library included with the Arduino IDE. This page documents every function and constant used across the sketches, with parameter types, return values, and usage notes. All examples target the Arduino UNO with CS on pin 10, MOSI on pin 11, MISO on pin 12, and SCK on pin 13.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/manish04-mu/TheEmbeddedInsights/llms.txt
Use this file to discover all available pages before exploring further.
SPI.begin()
Initializes the SPI bus in master mode. Internally configures SCK (pin 13), MOSI (pin 11), and SS (pin 10) as outputs and sets the default clock, bit order, and data mode. Note that SPI.begin() does not configure the user-defined CS pin — you must call pinMode(CS, OUTPUT) and digitalWrite(CS, HIGH) yourself in setup() before calling SPI.begin().
Parameters: none
Returns: void
SPISettings
Constructor that encapsulates all SPI bus configuration into a single object. Always pass an SPISettings instance to SPI.beginTransaction() — never set clock speed or data mode globally, as SPISettings ensures safe use alongside other libraries.
Bus clock frequency in Hz. The Arduino UNO supports up to 16,000,000 (16 MHz). All The Embedded Insights sketches use 100,000 (100 kHz) to stay comfortably within typical logic analyzer sampling limits.
Transmission bit order. Use
MSBFIRST to send bit 7 first (most significant), or LSBFIRST to send bit 0 first (least significant). Most SPI slaves expect MSBFIRST; consult the slave datasheet.Clock polarity and phase setting. One of
SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3. Each mode determines the clock idle state (CPOL) and the edge on which data is sampled (CPHA). See the Data Mode Constants table below.SPI.beginTransaction(settings)
Acquires the SPI bus with the configuration specified in settings. This must be called before asserting the CS pin — doing so in the correct order prevents bus contention when multiple libraries share the SPI hardware. All subsequent calls to SPI.transfer() use the clock speed, bit order, and data mode captured in settings.
Parameters:
An
SPISettings object created with the desired clock speed, bit order, and data mode.void
SPI.transfer(value)
Transfers one byte over the SPI bus using full-duplex communication. While value is shifted out on MOSI, one byte is simultaneously shifted in from the slave on MISO. The function blocks until all 8 bits have been clocked out and back.
Parameters:
The byte to transmit on MOSI. In the sketches this is typically a literal hex value such as
0x62 or a character from a string.byte — the byte received from the slave on MISO during the same clock cycle. Returns 0x00 when no slave is connected (MISO line floats or is pulled LOW).
SPI.endTransaction()
Releases the SPI bus, allowing other code or interrupt-driven libraries to use it. Deassert (pull HIGH) the CS pin before calling endTransaction() — the slave must be deselected before the bus is relinquished so that no partial transaction is left open.
Parameters: none
Returns: void
Data Mode Constants
The SPI data mode determines two things: the clock polarity (CPOL — idle state of SCK) and the clock phase (CPHA — which clock edge latches data). Choose the mode that matches your slave device’s datasheet.| Constant | CPOL | CPHA | Description |
|---|---|---|---|
SPI_MODE0 | 0 | 0 | Clock idles LOW; data sampled on rising edge |
SPI_MODE1 | 0 | 1 | Clock idles LOW; data sampled on falling edge |
SPI_MODE2 | 1 | 0 | Clock idles HIGH; data sampled on falling edge |
SPI_MODE3 | 1 | 1 | Clock idles HIGH; data sampled on rising edge |
Bit Order Constants
| Constant | Behavior |
|---|---|
MSBFIRST | Bit 7 (most significant bit) sent first |
LSBFIRST | Bit 0 (least significant bit) sent first |
Complete Transaction Pattern
Every sketch in The Embedded Insights follows the same five-step structure. Copy this pattern as your baseline and adjust theSPISettings arguments to match the target slave:
Always call
SPI.beginTransaction() before asserting CS, and deassert CS before calling SPI.endTransaction(). Reversing this order can corrupt ongoing transfers if another library uses the SPI bus inside an interrupt.