Module esp32_hal::spi::master

source ·
Expand description

§Serial Peripheral Interface - Master Mode

§Overview

There are multiple ways to use SPI, depending on your needs. Regardless of which way you choose, you must first create an SPI instance with Spi::new.

§Example

let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio12;
let miso = io.pins.gpio11;
let mosi = io.pins.gpio13;
let cs = io.pins.gpio10;

let mut spi = hal::spi::Spi::new(
    peripherals.SPI2,
    100u32.kHz(),
    SpiMode::Mode0,
    &mut peripheral_clock_control,
    &mut clocks,
)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));

§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:

  • Use the FullDuplex trait to read/write single bytes at a time,
  • Use the SpiBus trait (requires the “eh1” feature) and its associated functions to initiate transactions with simultaneous reads and writes, or
  • Use the ExclusiveDevice struct from embedded-hal-bus or SpiDevice from embassy-embedded-hal.

§Shared SPI access

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

Modules§

Structs§

  • SPI peripheral driver

Enums§

Traits§