Skip to main content
Clock data in and out of a SPI peripheral from the box, with full control over mode, bit order, word size and chip select.

Handle

Methods

Types

SpiConfig

A None field keeps the net’s saved value. Anything set is applied live and persisted on the box.

SpiOptions

SpiTransfer

Method Reference

configure(config: &SpiConfig) -> Result<SpiEffectiveConfig>

Apply settings and read back what took effect.

read(n_words: u32, opts: &SpiOptions) -> Result<SpiTransfer>

Clock in n_words, clocking out opts.fill for each.

write(data: &[u32], opts: &SpiOptions) -> Result<SpiTransfer>

Clock out exactly data. SPI is full duplex, so the words clocked in during the same transaction come back in the result — a write is also a read.

read_write(data: &[u32], opts: &SpiOptions) -> Result<SpiTransfer>

Full-duplex transfer of exactly data.

transfer(data: &[u32], n_words: u32, opts: &SpiOptions) -> Result<SpiTransfer>

Transfer exactly n_words, padding data with the fill word or truncating it.

Examples

Read a flash chip’s JEDEC ID

Hold CS across two transactions

Supported Hardware

Notes

  • opts.fill is only sent for read() and transfer(). write() and read_write() clock out exactly the data given, so a fill word would be meaningless.
  • word_size comes back on every transfer because a bus configured for 16-bit words returns half as many entries as you might expect from a byte count.
  • Transactions run on the box under the device’s lock, so a multi-word transfer cannot be interleaved by another request on the same device.
  • configure() persists across tests. Set what you depend on rather than assuming.