I am continuing porting my CircuitPython code to a RPi Zero. I ran into a serious problem attempting to use the secondary SPI bus, getting an "Invalid argument" error in Adafruit_PureIO/spi.py when I try to call write_readinto(), same error occurs however when attempting to use write() or readinto().
Traceback (most recent call last):
File "/home/pi/code.py", line 367, in spi_rw
self.spi.write_readinto(buf, data)
File "/home/pi/.local/lib/python3.7/site-packages/busio.py", line 311, in write_readinto
buffer_out, buffer_in, out_start, out_end, in_start, in_end
File "/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 128, in write_readinto
self._spi.mode = self.mode
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/spi.py", line 346, in mode
self._ioctl(SPI._IOC_WR_MODE, mode)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/spi.py", line 215, in _ioctl
ioctl(self.handle, ioctl_bytes, arg)
OSError: [Errno 22] Invalid argument
In a nutshell, this is what I am doing:
cs = digitalio.DigitalInOut(board.D18)
spi = busio.SPI(board.SCK_1, MOSI=board.MOSI_1, MISO=board.MISO_1)
device = SPIDevice(spi, cs, baudrate=2000000, polarity=0, phase=1)
# After the above initialization, I do this:
buf = bytearray(len)
data = bytearray(len)
# buf is filled with some data where len is a reasonable value, like 10
# ...
# then I do this...
with self.device:
spi.write_readinto(buf, data)
My code ran perfectly on my Feather M4, using bitbangio and different pins for the second SPI of course. I definitely need some help.