Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

RPi Zero CircuitPython issue with Secondary SPI bus
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RPi Zero CircuitPython issue with Secondary SPI bus

by ronfischler on Fri Jul 31, 2020 4:50 pm

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.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero CircuitPython issue with Secondary SPI bus

by ronfischler on Sat Aug 01, 2020 2:40 am

An update to this issue...

If I set the SPI mode to 0, then the argument error in Adafruit_PureIO/spi.py does not occur. Unfortunately, it appears that busio.SPI() and bitbangio.SPI() only work with mode 0, when using Blinka. Can this be fixed, or is there something I can do? I am using a SPI device that requires mode 1. The crash in spi.py occurs when calling ioctl() to set the mode to 1.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Re: RPi Zero CircuitPython issue with Secondary SPI bus

by ronfischler on Mon Aug 03, 2020 2:57 pm

Another update...

This issue has nothing to do with CircuitPython or Python on the RPi Zero. It seems that the RPi alternate SPI port simply does not support phase=1.

ronfischler
 
Posts: 27
Joined: Thu Jul 23, 2020 3:15 pm

Please be positive and constructive with your questions and comments.