SPI is a serial protocol that has exclusive pins for data in and out of the
master. It is typically faster than
I2C because a
separate pin is used to control the active slave rather than a transmitted
address. This class only manages three of the four SPI lines:
MISO. Its up to the client to manage the appropriate slave
select line. (This is common because multiple slaves can share the
MISO lines and therefore the hardware.)
SPI(clock, MOSI=None, MISO=None)¶
- Construct an SPI object on the given pins.
Turn off the SPI bus.
No-op used by Context Managers.
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
configure(*, baudrate=100000, polarity=0, phase=0, bits=8)¶
Configures the SPI bus. Only valid when locked.
Attempts to grab the SPI lock. Returns True on success.
Returns: True when lock has been grabbed Return type: bool
Releases the SPI lock.
Write the data contained in
buf. Requires the SPI being locked. If the buffer is empty, nothing happens.
Read into the buffer specified by
bufwhile writing zeroes. Requires the SPI being locked. If the number of bytes to read is 0, nothing happens.
write_readinto(buffer_out, buffer_in, *, out_start=0, out_end=None, in_start=0, in_end=None)¶
Write out the data in
buffer_outwhile simultaneously reading data into
buffer_in. The lengths of the slices defined by
buffer_in[in_start:in_end]must be equal. If buffer slice lengths are both 0, nothing happens.
- buffer_out (bytearray) – Write out the data in this buffer
- buffer_in (bytearray) – Read data into this buffer
- out_start (int) – Start of the slice of buffer_out to write out:
- out_end (int) – End of the slice; this index is not included. Defaults to
- in_start (int) – Start of the slice of
buffer_into read into:
- in_end (int) – End of the slice; this index is not included. Defaults to