Expand description
Asynchronous shared SPI bus
§Example (nrf52)
ⓘ
use embassy_embedded_hal::shared_bus::spi::SpiDevice;
use embassy_sync::mutex::Mutex;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
static SPI_BUS: StaticCell<Mutex<NoopRawMutex, spim::Spim<SPI3>>> = StaticCell::new();
let mut config = spim::Config::default();
config.frequency = spim::Frequency::M32;
let spi = spim::Spim::new_txonly(p.SPI3, Irqs, p.P0_15, p.P0_18, config);
let spi_bus = Mutex::new(spi);
let spi_bus = SPI_BUS.init(spi_bus);
// Device 1, using embedded-hal-async compatible driver for ST7735 LCD display
let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard);
let spi_dev1 = SpiDevice::new(spi_bus, cs_pin1);
let display1 = ST7735::new(spi_dev1, dc1, rst1, Default::default(), 160, 128);
// Device 2
let cs_pin2 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard);
let spi_dev2 = SpiDevice::new(spi_bus, cs_pin2);
let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128);
Structs§
- SPI device on a shared bus.
- SPI device on a shared bus, with its own configuration.