Available on crate feature
unstable
only.Expand description
§Serial Peripheral Interface - Slave Mode
§Overview
In this mode, the SPI acts as slave and transfers data with its master when its CS is asserted.
§Configuration
The SPI slave driver allows using full-duplex and can only be used with DMA.
§Examples
§SPI Slave with DMA
let dma_channel = peripherals.DMA_CH0;
let sclk = peripherals.GPIO0;
let miso = peripherals.GPIO1;
let mosi = peripherals.GPIO2;
let cs = peripherals.GPIO3;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
dma_buffers!(32000);
let mut spi = Spi::new(
peripherals.SPI2,
Mode::_0,
)
.with_sck(sclk)
.with_mosi(mosi)
.with_miso(miso)
.with_cs(cs)
.with_dma(
dma_channel,
rx_descriptors,
tx_descriptors,
);
let mut receive = rx_buffer;
let mut send = tx_buffer;
let transfer = spi
.transfer(&mut receive, &mut send)?;
transfer.wait()?;
§Implementation State
This driver is currently unstable.
There are several options for working with the SPI peripheral in slave mode, but the code currently only supports:
- Single transfers (not segmented transfers)
- Full duplex, single bit (not dual or quad SPI)
- DMA mode (not CPU mode).
It also does not support blocking operations, as the actual
transfer is controlled by the SPI master; if these are necessary,
then the
DmaTransfer
object can bewait()
ed on or polled foris_done()
.
See tracking issue for more information.
Modules§
- dma
- DMA (Direct Memory Access) functionality (Slave).
Structs§
- Spi
- SPI peripheral driver.