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 \ Remap | 0 (default) | 1 |
---|---|---|
SCK (A-PP : I-F) | PA5 | PB3 |
MISO (I-F/PU : A-PP/OD) | PA6 | PB4 |
MOSI (A-PP : I-F/PU) | PA7 | PB5 |
§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 \ Remap | 0 (default) | 1 (conn. devices) |
---|---|---|
SCK (A-PP : I-F) | PB3 | PC10 |
MISO (I-F/PU : A-PP/OD) | PB4 | PC11 |
MOSI (A-PP : I-F/PU) | PB5 | PC12 |
§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§
Enums§
- Error
- SPI error
- Event
- Interrupt event
- Phase
- Clock phase
- Polarity
- Clock polarity
- SpiBit
Format - The bit format to send the data in