Struct rppal::spi::Spi [−][src]
pub struct Spi { /* fields omitted */ }
Expand description
Provides access to the Raspberry Pi’s SPI peripherals.
Before using Spi
, make sure your Raspberry Pi has the necessary SPI buses
and Slave Select pins enabled. More information can be found here.
The embedded-hal
blocking::spi::Transfer<u8>
, blocking::spi::Write<u8>
and spi::FullDuplex<u8>
trait
implementations for Spi
can be enabled by specifying the optional hal
feature in the dependency declaration for the rppal
crate.
Implementations
Constructs a new Spi
.
bus
and slave_select
specify the selected SPI bus and one of its
associated Slave Select pins.
clock_speed
defines the maximum clock frequency in hertz (Hz). The SPI driver
will automatically round down to the closest valid frequency.
mode
selects the clock polarity and phase.
Sets the order in which bits are shifted out and in.
The Raspberry Pi currently only supports the MsbFirst
bit order. If you
need the LsbFirst
bit order, you can use the reverse_bits
function
instead to reverse the bit order in software by converting your write
buffer before sending it to the slave device, and your read buffer after
reading any incoming data.
By default, bit_order
is set to MsbFirst
.
Gets the number of bits per word.
Sets the number of bits per word.
The Raspberry Pi currently only supports 8 bit words.
By default, bits_per_word
is set to 8.
Gets the clock frequency in hertz (Hz).
Sets the clock frequency in hertz (Hz).
The SPI driver will automatically round down to the closest valid frequency.
Sets the SPI mode.
The SPI mode indicates the serial clock polarity and phase. Some modes may not be available depending on the SPI bus that’s used.
Gets the Slave Select polarity.
Sets Slave Select polarity.
By default, the Slave Select polarity is set to ActiveLow
.
Receives incoming data from the slave device and writes it to buffer
.
The SPI protocol doesn’t indicate how much incoming data is waiting,
so the total number of bytes read depends on the length of buffer
.
During the read, the MOSI line is kept in a state that results in a
zero value byte shifted out for every byte read
receives on the MISO
line.
Slave Select is set to active at the start of the read, and inactive when the read completes.
Returns how many bytes were read.
Sends the outgoing data contained in buffer
to the slave device.
Any data received on the MISO line from the slave is ignored.
Slave Select is set to active at the start of the write, and inactive when the write completes.
Returns how many bytes were written.
Sends and receives data at the same time.
SPI is a full-duplex protocol that shifts out bits to the slave device
on the MOSI line while simultaneously shifting in bits it receives on
the MISO line. transfer
stores the incoming data in read_buffer
,
and sends the outgoing data contained in write_buffer
.
Because data is sent and received simultaneously, transfer
will only
transfer as many bytes as the shortest of the two buffers contains.
Slave Select is set to active at the start of the transfer, and inactive when the transfer completes.
Returns how many bytes were transferred.
Transfers multiple half-duplex or full-duplex segments.
transfer_segments
transfers multiple segments in a single call. Each
Segment
contains a reference to either a read buffer or a write buffer,
or both. Optional settings can be configured that override the SPI bus
settings for that specific segment.
By default, Slave Select stays active until all segments have been
transferred. You can change this behavior using Segment::set_ss_change
.
Trait Implementations
FullDuplex<u8>
trait implementation for embedded-hal
v1.0.0-alpha.5.
FullDuplex<u8>
trait implementation for embedded-hal
v0.2.6.
Transfer<u8>
trait implementation for embedded-hal
v1.0.0-alpha.5.
Transfer<u8>
trait implementation for embedded-hal
v0.2.6.
Write<u8>
trait implementation for embedded-hal
v1.0.0-alpha.5.
Write<u8>
trait implementation for embedded-hal
v0.2.6.