def _set_rate(self, value): self._check_open() value = int(value) lgpio.spi_close(self._handle) self._baud = value self._handle = lgpio.spi_open(self._port, self._device, self._baud, self._spi_flags)
def _set_clock_mode(self, value): self._check_open() if not 0 <= value < 4: raise SPIInvalidClockMode("%d is not a valid SPI clock mode" % value) lgpio.spi_close(self._handle) self._spi_flags = value self._handle = lgpio.spi_open( self._port, self._device, self._baud, self._spi_flags)
def __init__(self, clock_pin, mosi_pin, miso_pin, select_pin, pin_factory): port, device = spi_port_device( clock_pin, mosi_pin, miso_pin, select_pin) self._port = port self._device = device self._baud = 500000 self._spi_flags = 0 self._handle = None super(LGPIOHardwareSPI, self).__init__(pin_factory=pin_factory) to_reserve = {clock_pin, select_pin} if mosi_pin is not None: to_reserve.add(mosi_pin) if miso_pin is not None: to_reserve.add(miso_pin) self.pin_factory.reserve_pins(self, *to_reserve) self._handle = lgpio.spi_open(port, device, self._baud, self._spi_flags)
status = sbc.serial_write(9999, []) check("serial_write 1", sbc.BAD_SERIAL_PARAM, status) status = sbc.serial_write(9999, [88, 77, 66, 55, 44, 33, 22, 11]) check("serial_write 2", sbc.BAD_HANDLE, status) status = sbc.serial_write_byte(9999, 256) check("serial_write_byte 2", sbc.BAD_SERIAL_PARAM, status) status = sbc.serial_write_byte(9999, 88) check("serial_write_byte 2", sbc.BAD_HANDLE, status) status = sbc.spi_close(9999) check("spi_close 1", sbc.BAD_HANDLE, status) status = sbc.spi_open(2, 1, 7777, 6666) check("spi_open 1", sbc.SPI_OPEN_FAILED, status) status, dummy = sbc.spi_read(9999, 0) check("spi_read 1", sbc.BAD_SPI_COUNT, status) status, dummy = sbc.spi_read(9999, 8888) check("spi_read 2", sbc.BAD_HANDLE, status) status = sbc.spi_write(9999, []) check("spi_write 1", sbc.BAD_SPI_COUNT, status) status = sbc.spi_write(9999, [88, 77, 66, 55, 44, 33, 22, 11]) check("spi_write 2", sbc.BAD_HANDLE, status) status, dummy = sbc.spi_xfer(9999, [])
import time import lgpio as sbc MCP23017_1 = 0x20 MCP23017_2 = 0x21 NANO = 0x2c DAC_CS = 8 # spidev 0.0 ADC_CS = 25 # spidev 0.1 NANO_CS = 24 # spidev 0.1 chip = sbc.gpiochip_open(0) sbc.gpio_claim_output(chip, ADC_CS, 1) sbc.gpio_claim_output(chip, NANO_CS, 1) dac = sbc.spi_open(0, 0, 50000) others = sbc.spi_open(0, 1, 50000) nano_i2c = sbc.i2c_open(1, NANO) nano_serial = sbc.serial_open("serial0", 115200) inc = True potpos = 0 while True: while True: sbc.spi_write(dac, [0, potpos])