Comments (6)
According to https://www.raspberrypi.org/forums/viewtopic.php?t=124472&p=837140#p1138833, there are several occurances of the magic number 4096 (hardcoded).
Searching myself, it just seems to be defined here:
Line 31 in a76493f
So your error is likely unrelated. You could try to check the arguments' type or ensure they are int.
sudo python3 setup.py install
However, changing the buffer size works surprisingly easy (Raspbian Stretch lite with some prior build setups I don't remember, so you may have to figure out some dependencies):
- add spidev.bufsiz=32768 to the line in /boot/cmdline.txt and reboot sometime
- test with
cat /sys/module/spidev/parameters/bufsiz
- test with
git clone https://github.com/doceme/py-spidev.git
cd py-spidev/
nano spidev_module.c
- change
#define SPIDEV_MAXPATH 4096
- change
make PYTHON=python3
sudo python3 setup.py install
rm -rf py-spidev/
from py-spidev.
@gnbl, your solution works without problems. Thanks!
from py-spidev.
Okay, @doceme , here comes the patch :) #75
I decided not to touch any of the existing methods and added xfer3
. It accepts lists of arbitrary size and splits large lists into smaller chunks and transfers them.
It also gets maximum SPI buffer size from /sys/module/spidev/parameters/bufsiz
but caps it to 65535 because I believe DMA is not possible with larger buffers. If it fails to read /sys/module/spidev/parameters/bufsiz
, it defaults to the standard 4K.
I have very little knowledge on Python C APIs so I do not really understand tricks in the original code like this one https://github.com/doceme/py-spidev/blob/master/spidev_module.c#L450-L453 . However from what I read, it looks like PySequence_Fast
increments the counter even if it returns you the same object so you always have to do Py_DECREF(seq)
which original code does not do in many cases (like error handling or just the normal return). Again, not sure about all of this.
from py-spidev.
Would be much better if spidev either
- allowed changing the buffer size with a method call. The buffers for
xfer
are allocated in thexfer
itself so just in theory the size can be changed between calls toxfer
no problem - or just hid the fact that buffer of limited size is used - it can collect a chunk of data from the list passed to fill the buffer, flush it, collect the next chunk etc. Because this is what people end up doing anyway
for i in range(0, len(data), chunk_size):
chunk = data[i:i + chunk_size]
self.spi.xfer(chunk)
it works, just not as efficient as it would be if done by xfer
itself.
Still, allowing setting buffer size may not be the worst idea too because by changing /sys/module/spidev/parameters/bufsiz
(on Raspberry at least) I can increase that buffer but there is no way to communicate this optimisation to spidev
. (Well, if spidev
hid the fact it is using limited buffer AND also got default size from this file that would be just brilliant, right? :) )
from py-spidev.
Pull request are welcome. 😉
from py-spidev.
I had follow this tutorial and the problem had fixed: https://youtu.be/1VJDhAClKMc.
Thanks.
from py-spidev.
Related Issues (20)
- Reading from SPI 0.0 is always zero HOT 3
- CS line double pulsing HOT 3
- spurious low pulse on CS0 HOT 28
- SPI CE0 bounce problem HOT 1
- after close and recreate got Bad file decriptor HOT 1
- The CS_HIGH handling code triggers a lockup on Raspberry Pi in 5.10 HOT 3
- [RPi 4] Spurious CS pulse after transfer HOT 3
- Type interface to writebytes not clear HOT 1
- RX buffer overwrites the TX buffer in 'xfer2' HOT 2
- "xfer2"/"xfer" command erases slave data / slave is unable to respond HOT 6
- support for python 3.9.4 HOT 1
- Please tag 3.5 version
- Unexpected SCK behavior
- Installation Python Spidev fails on Alpine Linux aarch64 HOT 3
- How to define a GPIO pin of Raspberry Pi while I'm using spidev lib? HOT 1
- Install failing on macos [missing linux/spi/spidev.h] HOT 1
- Supporting with-statements
- The open() method is not well suited to hot-plugged SPI device controllers (e.g. USB, Thunderbolt, PCIe and similar situations). HOT 2
- Could not build wheels for spidev HOT 2
- Quad and Dual format support for Synopsys Enhanced SPI controllers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-spidev.