adafruit_bus_device.spi_device – SPI Device Manager¶
- class adafruit_bus_device.spi_device.SPIDevice(spi: busio.SPI, chip_select: microcontroller.Pin, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, extra_clocks: int = 0)¶
Represents a single SPI device and manages locking the bus and the device address.
spi (SPI) – The SPI bus the device is on
chip_select (DigitalInOut) – The chip select pin object that implements the DigitalInOut API.
cs_active_value (bool) – Set to true if your device requires CS to be active high. Defaults to false.
extra_clocks (int) – The minimum number of clock cycles to cycle the bus after CS is high. (Used for SD cards.)
import busio import digitalio from board import * from adafruit_bus_device.spi_device import SPIDevice with busio.SPI(SCK, MOSI, MISO) as spi_bus: cs = digitalio.DigitalInOut(D10) device = SPIDevice(spi_bus, cs) bytes_read = bytearray(4) # The object assigned to spi in the with statements below # is the original spi_bus object. We are using the busio.SPI # operations busio.SPI.readinto() and busio.SPI.write(). with device as spi: spi.readinto(bytes_read) # A second transaction with device as spi: spi.write(bytes_read)
- __enter__(self) busio.SPI ¶
Starts a SPI transaction by configuring the SPI and asserting chip select.