Coder Social home page Coder Social logo

spurious low pulse on CS0 about py-spidev HOT 28 CLOSED

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024 2
spurious low pulse on CS0

from py-spidev.

Comments (28)

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024 1

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.

semininja avatar semininja commented on August 23, 2024 1

@jfernandz xfer() writes data and reads the response at the same time, while writedata() ignores the MISO line (returned data).

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024 1

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.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024 1

@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.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

Upgrading to spidev-3.5 did not fix this issue!

from py-spidev.

jfernandz avatar jfernandz commented on August 23, 2024

I'm having exactly the same problem

DS0002

Apparently it's a known behavior https://www.raspberrypi.org/forums/viewtopic.php?p=1781304#p1777594

from py-spidev.

jfernandz avatar jfernandz commented on August 23, 2024

@MikeD2-mnb what's actually the difference between xfer() and writedata()?

from py-spidev.

Inbethath avatar Inbethath commented on August 23, 2024

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):
image

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

fgr1986 avatar fgr1986 commented on August 23, 2024

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.

Inbethath avatar Inbethath commented on August 23, 2024

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.

antgraf avatar antgraf commented on August 23, 2024

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:
pi

from py-spidev.

doceme avatar doceme commented on August 23, 2024

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.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

doceme avatar doceme commented on August 23, 2024

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.

doceme avatar doceme commented on August 23, 2024

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.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

doceme avatar doceme commented on August 23, 2024

Version 3.6 was just released last night. You should be able to do: sudo pip install spidev --upgrade

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

doceme avatar doceme commented on August 23, 2024

Did you try with the --upgrade flag after pip install spidev? Yes, I was up late last night. 😴

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

doceme avatar doceme commented on August 23, 2024

Are you using a 64-bit kernel? What is the output of uname -a command?

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

doceme avatar doceme commented on August 23, 2024

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.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

MikeD2-mnb avatar MikeD2-mnb commented on August 23, 2024

from py-spidev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.