Comments (28)
the function writedata() doesn't do this, so why should xfer()? (xfer2 & 3 also do this.
lines in the source code indicate that the author / maintainer are aware of the problem, and have tried to fix it:
// WA:
// in CS_HIGH mode CS isn't pulled to low after transfer, but after read
// reading 0 bytes doesnt matter but brings cs down
// tomdean:
// Stop generating an extra CS except in mode CS_HOGH
if (self->mode & SPI_CS_HIGH) status = read(self->fd, &rxbuf[0], 0);
from py-spidev.
@jfernandz xfer()
writes data and reads the response at the same time, while writedata()
ignores the MISO line (returned data).
from py-spidev.
Thanks MetaStasisa, This IS the fix, but needs to be applied in 3 places xfer, xfer2 and xfer3. The package can then be re-installed using "sudo python3 setup.py install|" from the directory with the source.
from py-spidev.
@fgr1968,
Until the maintainer of the code realises that the additional lines need commenting out again, the patch will have to be done by hand. As the code is stable at the moment - I haven;'t found any other bugs - I think that we are going to have to check for this bug after every update. So if you have an application where this is critical (I have 2) this will be a pain. Target slave devices SHOULD ignore stray chip enable pulses if there is no valid start condition, but particularly wit chips for the automotive industry, this seems not to be the case. Mike.
from py-spidev.
Upgrading to spidev-3.5 did not fix this issue!
from py-spidev.
I'm having exactly the same problem
Apparently it's a known behavior https://www.raspberrypi.org/forums/viewtopic.php?p=1781304#p1777594
from py-spidev.
@MikeD2-mnb what's actually the difference between xfer()
and writedata()
?
from py-spidev.
So - I had this issue as well @MikeD2-mnb
I've had to manually go into the spidev_module.c file and simply commented the if statement.
// WA:
// in CS_HIGH mode CS isn't pulled to low after transfer, but after read
// reading 0 bytes doesnt matter but brings cs down
// tomdean:
// Stop generating an extra CS except in mode CS_HOGH
// if (self->mode & SPI_CS_HIGH) status = read(self->fd, &rxbuf[0], 0);
Then I rebuilt it using pip install .
directly from the source
I suspect it might've been a bug at some point so it was necessary for the driver to read 0 bytes. I'm unsure if it remains an issue but simply commenting that code fixed the issue for me and SPI seems to be working properly again.
For reference here's how it looks like now (I'm using a logic analyzer):
from py-spidev.
from py-spidev.
Hi, @MikeD2-mnb , @MetaStasisa
Will this patch be incorporated in the main branch in the future? or shall we re-patch with every release?
Thanks
from py-spidev.
Hey @fgr1986 ,
It appears that code was baked in due to a certain bug - I'm unsure if that bug has been resolved or not. Therefore, I haven't put in a pull request for these changes.
I think @doceme might be the best person to answer this if they're available.
Thanks,
Meta
from py-spidev.
I do confirm the same for xfer3(). I'd say it's a major bug which blocks a number of devices from operation. Such as ADS7066 from Texas Instruments.
See green signal:
from py-spidev.
The extra read referenced in this issue has been disabled by default as of version 3.6 and can be re-enabled using the read0 flag for any platform that still requires it.
from py-spidev.
from py-spidev.
If you explicitly set the read0 flag to False
before the transfer, are you still seeing the spurious low pulses on CS for BBB?
from py-spidev.
Sorry, I misunderstood. You're saying the problem exists in the Adafruit BBIO library, not py-spidev. Yes, that project has an unconditional read here and here that will have to be fixed in that project.
from py-spidev.
from py-spidev.
Version 3.6 was just released last night. You should be able to do: sudo pip install spidev --upgrade
from py-spidev.
from py-spidev.
Did you try with the --upgrade
flag after pip install spidev
? Yes, I was up late last night. 😴
from py-spidev.
from py-spidev.
from py-spidev.
Are you using a 64-bit kernel? What is the output of uname -a
command?
from py-spidev.
from py-spidev.
I forgot to upload the source along with the binary when I released version 3.6 to PyPI, so piwheels didn't pick it up. I have since uploaded the source. Can you try pip install spidev --upgrade
again?
from py-spidev.
from py-spidev.
from py-spidev.
from py-spidev.
Related Issues (20)
- Reading from SPI 0.0 is always zero HOT 3
- CS line double pulsing HOT 3
- 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.