Import
Methods
| Method | Description |
|---|---|
config() | Configure SPI bus parameters |
read() | Read words from a device (sends fill bytes) |
read_write() | Simultaneous full-duplex read and write |
transfer() | Transfer with automatic padding/truncation |
write() | Write words to a device (discards response) |
get_config() | Get raw net configuration |
Method Reference
Net.get(name, type=NetType.SPI)
Get an SPI net by name.
| Parameter | Type | Description |
|---|---|---|
name | str | Name of the SPI net |
type | NetType | Must be NetType.SPI |
config(mode, bit_order, frequency_hz, word_size, cs_active, cs_mode)
Configure SPI bus parameters. Only explicitly-provided parameters are changed; omitted parameters retain their stored values.
| Parameter | Type | Description |
|---|---|---|
mode | int or None | SPI mode 0-3 (see SPI Modes table below) |
bit_order | str or None | "msb" (most significant bit first) or "lsb" |
frequency_hz | int or None | Clock frequency in Hz |
word_size | int or None | Bits per word: 8, 16, or 32 |
cs_active | str or None | Chip select polarity: "low" or "high" |
cs_mode | str or None | "auto" (hardware CS) or "manual" (user-managed GPIO) |
SPI Modes
| Mode | CPOL | CPHA | Clock Idle | Sample Edge |
|---|---|---|---|---|
| 0 | 0 | 0 | Low | Rising |
| 1 | 0 | 1 | Low | Falling |
| 2 | 1 | 0 | High | Falling |
| 3 | 1 | 1 | High | Rising |
read(n_words, fill, keep_cs, output_format)
Read data from an SPI device. Sends fill bytes while receiving data (full duplex).
| Parameter | Type | Description |
|---|---|---|
n_words | int | Number of words to read |
fill | int | Fill value sent while reading (default 0xFF) |
keep_cs | bool | Keep CS asserted after transfer (default False) |
output_format | str | "list" (default), "hex", "bytes", or "json" |
list[int] - Received words as integers (when output_format="list")
read_write(data, keep_cs, output_format)
Perform simultaneous full-duplex SPI read and write. Sends data while simultaneously receiving the response.
| Parameter | Type | Description |
|---|---|---|
data | list[int] | Words to transmit |
keep_cs | bool | Keep CS asserted after transfer (default False) |
output_format | str | "list" (default), "hex", "bytes", or "json" |
list[int] - Received words (same length as transmitted data)
transfer(n_words, data, fill, keep_cs, output_format)
Perform SPI transfer with automatic padding or truncation. If data is shorter than n_words, it is padded with the fill value. If longer, it is truncated.
| Parameter | Type | Description |
|---|---|---|
n_words | int | Total number of words to transfer |
data | list[int] or None | Words to transmit (padded/truncated to n_words) |
fill | int | Fill value for padding (default 0xFF) |
keep_cs | bool | Keep CS asserted after transfer (default False) |
output_format | str | "list" (default), "hex", "bytes", or "json" |
list[int] - Received words
write(data, keep_cs)
Write data to an SPI device, discarding the response. Convenience method for write-only operations.
| Parameter | Type | Description |
|---|---|---|
data | list[int] | Words to transmit |
keep_cs | bool | Keep CS asserted after transfer (default False) |
get_config()
Get the raw net configuration dictionary.
dict - Full net configuration including name, role, instrument, and params
Output Formats
Theoutput_format parameter controls how data is returned. Hex formatting is word-size-aware:
| Format | Return Type | 8-bit Example | 16-bit Example |
|---|---|---|---|
"list" | list[int] | [222, 173] | [57005] |
"hex" | str | "de ad" | "dead" |
"bytes" | str | "222 173" | "57005" |
"json" | dict | {"data": [222, 173]} | {"data": [57005]} |
Examples
Read SPI Flash JEDEC ID
Read Flash Memory
Multi-Part Transaction with keep_cs
Write to SPI Flash
16-bit Word Mode
Supported Hardware
| Adapter | Description |
|---|---|
| LabJack T7 | Uses GPIO pins (FIO/EIO) for CLK, MOSI, MISO, and CS |
| Aardvark I2C/SPI | Dedicated USB SPI adapter with GPIO bit-bang |
Notes
- Net must be configured as
NetType.SPI - All SPI operations are full duplex; data is sent and received simultaneously
write()performs a full-duplex transfer but discards the received datakeep_cs=Trueholds the chip select line asserted between calls for multi-part transactionstransfer()pads short data arrays with the fill value or truncates long arrays ton_words- LabJack T7 supports up to 56 bytes per transaction and a maximum of approximately 800 kHz
- Aardvark uses GPIO bit-bang mode; actual speed is limited by USB round-trip time regardless of
frequency_hz - Configuration changes persist to
saved_nets.jsonfor subsequent commands - LSB-first mode (
bit_order="lsb") uses software bit reversal on LabJack T7

