Struct nrf52840_hal::Spim
source · pub struct Spim<T>(/* private fields */);
Expand description
Interface to a SPIM instance.
This is a very basic interface that comes with the following limitations:
- The SPIM instances share the same address space with instances of SPIS,
SPI, TWIM, TWIS, and TWI. You need to make sure that conflicting instances
are disabled before using
Spim
. See product specification, section 15.2.
Implementations§
source§impl<T> Spim<T>where
T: Instance,
impl<T> Spim<T>where
T: Instance,
pub fn new( spim: T, pins: Pins, frequency: FREQUENCY_A, mode: Mode, orc: u8 ) -> Spim<T>
sourcepub fn transfer(
&mut self,
chip_select: &mut Pin<Output<PushPull>>,
buffer: &mut [u8]
) -> Result<(), Error>
pub fn transfer( &mut self, chip_select: &mut Pin<Output<PushPull>>, buffer: &mut [u8] ) -> Result<(), Error>
Read and write from a SPI slave, using a single buffer.
This method implements a complete read transaction, which consists of the master transmitting what it wishes to read, and the slave responding with the requested data.
Uses the provided chip select pin to initiate the transaction. Transmits
all bytes in buffer
, then receives an equal number of bytes.
sourcepub fn transfer_split_even(
&mut self,
chip_select: &mut Pin<Output<PushPull>>,
tx_buffer: &[u8],
rx_buffer: &mut [u8]
) -> Result<(), Error>
pub fn transfer_split_even( &mut self, chip_select: &mut Pin<Output<PushPull>>, tx_buffer: &[u8], rx_buffer: &mut [u8] ) -> Result<(), Error>
Read and write from a SPI slave, using separate read and write buffers.
This method implements a complete read transaction, which consists of the master transmitting what it wishes to read, and the slave responding with the requested data.
Uses the provided chip select pin to initiate the transaction. Transmits
all bytes in tx_buffer
, then receives bytes until rx_buffer
is full.
If tx_buffer.len() != rx_buffer.len()
, the transaction will stop at the
smaller of either buffer.
sourcepub fn transfer_split_uneven(
&mut self,
chip_select: &mut Pin<Output<PushPull>>,
tx_buffer: &[u8],
rx_buffer: &mut [u8]
) -> Result<(), Error>
pub fn transfer_split_uneven( &mut self, chip_select: &mut Pin<Output<PushPull>>, tx_buffer: &[u8], rx_buffer: &mut [u8] ) -> Result<(), Error>
Read and write from a SPI slave, using separate read and write buffers.
This method implements a complete read transaction, which consists of the master transmitting what it wishes to read, and the slave responding with the requested data.
Uses the provided chip select pin to initiate the transaction. Transmits
all bytes in tx_buffer
, then receives bytes until rx_buffer
is full.
This method is more complicated than the other transfer
methods because
it is allowed to perform transactions where tx_buffer.len() != rx_buffer.len()
.
If this occurs, extra incoming bytes will be discarded, OR extra outgoing bytes
will be filled with the orc
value.
pub fn transfer_split_uneven_internal( &mut self, tx_buffer: &[u8], rx_buffer: &mut [u8] ) -> Result<(), Error>
Trait Implementations§
source§impl<T> SpiBus for Spim<T>where
T: Instance,
impl<T> SpiBus for Spim<T>where
T: Instance,
source§fn read(
&mut self,
words: &mut [u8]
) -> Result<(), <Spim<T> as ErrorType>::Error>
fn read( &mut self, words: &mut [u8] ) -> Result<(), <Spim<T> as ErrorType>::Error>
words
from the slave. Read moresource§fn write(&mut self, words: &[u8]) -> Result<(), <Spim<T> as ErrorType>::Error>
fn write(&mut self, words: &[u8]) -> Result<(), <Spim<T> as ErrorType>::Error>
words
to the slave, ignoring all the incoming words. Read moresource§fn transfer(
&mut self,
read: &mut [u8],
write: &[u8]
) -> Result<(), <Spim<T> as ErrorType>::Error>
fn transfer( &mut self, read: &mut [u8], write: &[u8] ) -> Result<(), <Spim<T> as ErrorType>::Error>
write
is written to the slave on MOSI and
words received on MISO are stored in read
. Read more