adafruit_bus_device.spi_device – SPI Device Manager
- class adafruit_bus_device.spi_device.SPIDevice(spi: busio.SPI, chip_select: digitalio.DigitalInOut | None = None, *, cs_active_value: bool = False, 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.
- Parameters:
spi (SPI) – The SPI bus the device is on
chip_select (DigitalInOut) – The chip select pin object that implements the DigitalInOut API.
Noneif a chip select pin is not being used.cs_active_value (bool) – Set to
Trueif your device requires CS to be active high. Defaults toFalse.baudrate (int) – the desired clock rate in Hertz. The value is treated as a ceiling: the actual clock rate may be lower due to the granularity of available clock settings, but it will not exceed the given value.
polarity (int) – the base state of the clock line (0 or 1)
phase (int) – the edge of the clock that data is captured. First (0) or second (1). Rising or falling depends on clock polarity.
extra_clocks (int) – The minimum number of clock cycles to cycle the bus after CS is high. (Used for SD cards.)
Example:
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)
- __exit__() None
Ends a SPI transaction by deasserting chip select. See Lifetime and ContextManagers for more info.