esp_hal::spi

Module master

Source
Expand description

§Serial Peripheral Interface - Master Mode

§Overview

In this mode, the SPI acts as master and initiates the SPI transactions.

§Configuration

The peripheral can be used in full-duplex and half-duplex mode and can leverage DMA for data transfers. It can also be used in blocking or async.

§Exclusive access to the SPI bus

If all you want to do is to communicate to a single device, and you initiate transactions yourself, there are a number of ways to achieve this:

§Shared SPI access

If you have multiple devices on the same SPI bus that each have their own CS line (and optionally, configuration), you may want to have a look at the implementations provided by embedded-hal-bus and embassy-embedded-hal.

§Usage

The module implements several third-party traits from embedded-hal@1.x.x and embassy-embedded-hal.

§Examples

§SPI Initialization

let sclk = peripherals.GPIO0;
let miso = peripherals.GPIO2;
let mosi = peripherals.GPIO1;

let mut spi = Spi::new(
    peripherals.SPI2,
    Config::default().with_frequency(100.kHz()).with_mode(Mode::_0)
)
.unwrap()
.with_sck(sclk)
.with_mosi(mosi)
.with_miso(miso);

Structs§

Enums§

  • Addressunstable
    SPI address, ranging from 1 to 32 bits, paired with a data mode.
  • Commandunstable
    SPI commands, each consisting of a 16-bit command value and a data mode.
  • Configuration errors.
  • SpiInterruptunstable
    Enumeration of possible SPI interrupt events.