Expand description
API for the SPI peripheral
The entry point to this API is the SPI struct.
The SPI peripheral is described in the following user manuals:
- LPC82x user manual, chapter 14
- LPC84x user manual, chapter 18
§Example
use lpc8xx_hal::{
prelude::*,
Peripherals,
spi,
};
let mut p = Peripherals::take().unwrap();
let mut swm = p.SWM.split();
let mut syscon = p.SYSCON.split();
#[cfg(feature = "82x")]
let mut swm_handle = swm.handle;
#[cfg(feature = "845")]
let mut swm_handle = swm.handle.enable(&mut syscon.handle);
let (spi0_sck, _) = swm.movable_functions.spi0_sck.assign(
p.pins.pio0_13.into_swm_pin(),
&mut swm_handle,
);
let (spi0_mosi, _) = swm
.movable_functions
.spi0_mosi
.assign(p.pins.pio0_14.into_swm_pin(), &mut swm_handle);
let (spi0_miso, _) = swm
.movable_functions
.spi0_miso
.assign(p.pins.pio0_15.into_swm_pin(), &mut swm_handle);
#[cfg(feature = "82x")]
let spi_clock = spi::Clock::new(&(), 0);
#[cfg(feature = "845")]
let spi_clock = spi::Clock::new(&syscon.iosc, 0);
// Enable SPI0
let mut spi = p.SPI0.enable_as_master(
&spi_clock,
&mut syscon.handle,
embedded_hal::spi::MODE_0,
spi0_sck,
spi0_mosi,
spi0_miso,
);
let mut tx_data = [0x00, 0x01];
let rx_data = spi.transfer(&mut tx_data)
.expect("Transfer shouldn't fail");Please refer to the examples in the repository for more example code.
Structs§
- Clock
- Contains the clock configuration for an SPI instance
- Interrupts
- Used to enable or disable SPI interrupts
- Master
- Indicates that SPI is in master mode
- Mode
- SPI mode
- SPI
- Interface to a SPI peripheral
- Slave
- Indicates that SPI is in slave mode
- Transfer
- An SPI/DMA transfer
Enums§
Constants§
- MODE_0
- Helper for CPOL = 0, CPHA = 0
- MODE_1
- Helper for CPOL = 0, CPHA = 1
- MODE_2
- Helper for CPOL = 1, CPHA = 0
- MODE_3
- Helper for CPOL = 1, CPHA = 1
Traits§
- Clock
Source - Implemented for SPI clock sources
- Instance
- Implemented for all SPI instance
- Slave
Select - Implemented for slave select functions of a given SPI instance