Module spi

Module spi 

Source
Expand description

§Serial Peripheral Interface

To construct the SPI instances, use the Spi::spiX functions.

The pin parameter is a tuple containing (Some(sck), Some(miso), Some(mosi)) which should be configured as (Alternate<...>, Input<...>, Alternate<...>). As some STM32F1xx chips have 5V tolerant SPI pins, it is also possible to configure Sck and Mosi outputs as Alternate<PushPull>. Then a simple Pull-Up to 5V can be used to use SPI on a 5V bus without a level shifter.

You can also use None::<PA6> or SPI1::NoMiso if you don’t want to use the pins

§Alternate function remapping

§SPI1

Function \ Remap0 (default)1
SCK (A-PP : I-F)PA5PB3
MISO (I-F/PU : A-PP/OD)PA6PB4
MOSI (A-PP : I-F/PU)PA7PB5

§SPI2

Function
SCK (A-PP : I-F)PB13
MISO (I-F/PU : A-PP/OD)PB14
MOSI (A-PP : I-F/PU)PB15

§SPI3

Function \ Remap0 (default)1 (conn. devices)
SCK (A-PP : I-F)PB3PC10
MISO (I-F/PU : A-PP/OD)PB4PC11
MOSI (A-PP : I-F/PU)PB5PC12

§Initialisation example

  // Acquire the GPIOB peripheral
  let mut gpiob = dp.GPIOB.split();

  let pins = (
      Some(gpiob.pb13.into_alternate_push_pull(&mut gpiob.crh)),
      Some(gpiob.pb14.into_floating_input(&mut gpiob.crh)),
      Some(gpiob.pb15.into_alternate_push_pull(&mut gpiob.crh)),
  );

  // or just

  let pins = (
      Some(gpiob.pb13),
      Some(gpiob.pb14),
      Some(gpiob.pb15),
  );

  let spi_mode = Mode {
      polarity: Polarity::IdleLow,
      phase: Phase::CaptureOnFirstTransition,
  };
  let spi = dp.SPI2.spi(pins, spi_mode, 100.khz(), &mut rcc);

Structs§

Mode
SPI mode
Spi
Spi in Master mode
SpiInner
SpiSlave
Spi in Slave mode

Enums§

Error
SPI error
Event
Interrupt event
Phase
Clock phase
Polarity
Clock polarity
SpiBitFormat
The bit format to send the data in

Traits§

FrameSize
Instance
SpiExt

Type Aliases§

Spi1RxDma
Spi1RxTxDma
Spi1TxDma
Spi2RxDma
Spi2RxTxDma
Spi2TxDma
SpiRxDma
SpiRxTxDma
SpiSlave1RxDma
SpiSlave1RxTxDma
SpiSlave1TxDma
SpiSlave2RxDma
SpiSlave2RxTxDma
SpiSlave2TxDma
SpiSlaveRxDma
SpiSlaveRxTxDma
SpiSlaveTxDma
SpiTxDma