Skip to main content
Perform SPI (Serial Peripheral Interface) data transfers with devices connected to a Lagerbox. SPI is a synchronous serial protocol using four lines: SCLK (clock), MOSI (master out), MISO (master in), and CS (chip select).

Syntax

Arguments

Options

When invoked without a subcommand, lists SPI nets on the box (or shows configuration for the specified net).

Subcommands

config

Configure SPI bus parameters. Settings persist across subsequent commands.
SPI Modes: Examples:

transfer

Perform a full-duplex SPI transfer. Sends data while simultaneously receiving response. If provided data is shorter than NUM_WORDS, the remaining words are padded with the fill value. If longer, data is truncated.
Examples:

read

Read data from an SPI slave device. Sends fill bytes while clocking in the response.
Examples:

write

Write data to an SPI slave device. Performs a full-duplex transfer and displays the received response.
Examples:

Hex Data Formats

Data arguments accept multiple hex formats. Parsing behavior depends on word size: 8-bit word size (default): 16-bit or 32-bit word size: Values are validated against the configured word size range.

Fill Value Format

The --fill option accepts hex or decimal values:

Frequency Format

Clock frequencies accept numeric values with optional suffixes:

Supported Hardware


Net Configuration

SPI nets are configured in saved_nets.json on the box. Example net record:
For Aardvark adapters:

Output Formats


Examples


Troubleshooting

No Response from Device

  • Verify MOSI, MISO, SCLK, and CS wiring
  • Check SPI mode matches the device datasheet
  • Confirm CS polarity (--cs-active low for most devices)
  • Try reducing frequency with --frequency 100k

Garbled Data

  • Verify SPI mode (CPOL/CPHA) matches the device
  • Check bit order (MSB vs LSB first)
  • Ensure word size matches the device protocol

CS Pin Not Working (LabJack T7)

  • LabJack T7 uses manual GPIO-based CS control
  • The driver automatically asserts/deasserts CS via GPIO writes
  • Verify the cs_pin in the net configuration matches your wiring

Notes

  • Default SPI net can be set with lager defaults add --spi-net NETNAME
  • LabJack T7 operates at ~450 kHz regardless of requested frequency due to hardware limitations
  • SPI is full-duplex: data is always sent and received simultaneously
  • Use --keep-cs for multi-part transactions that require CS to stay asserted
  • Configuration set via config persists across subsequent transfer/read/write commands

See Also

  • I2C — I2C bus communication (the other common serial protocol)
  • Python SPI API — Automate SPI operations in Python scripts
  • Glossary — Definitions of SPI, I2C, and other terms