Module slave

Source
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_SPI2;
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 dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap();
let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap();
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);

let transfer = spi
    .transfer(50, dma_rx_buf, 50, dma_tx_buf)?;

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).
  • ESP32 only supports SPI mode 1 and 3.

It also does not support blocking operations, as the actual transfer is controlled by the SPI master; if these are necessary, then the SpiDmaTransfer object can be wait()ed on or polled for is_done().

See tracking issue for more information.

Modules§

dma
DMA (Direct Memory Access) functionality (Slave).

Structs§

Spi
SPI peripheral driver.

Traits§

Instance
A peripheral singleton compatible with the SPI slave driver.