-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
writebytes/readbytes broken? #19
Comments
I second this. Readbytes and writebytes do not seem to be working. Instead I am using xfer and xfer2. |
Tested this on a Raspberry Pi 3, running Raspbian, Kernel 4.4.15 and Python 2.7.9. Ran, simply:
Results were exactly as expected. 9 groups of clock pulses on my scope, with each bit asserted at the right time. I used the repl to run the Same result sending: Can you identify your Pi, by running:
And I'll see if I can replicate on the same hardware. I haven't tested |
Unfortunately I can't. At the time I posted this issue I've worked on a project for my university. Now it's finished and I don't have access to the hardware anymore. But maybe @jainakshay91 can help you. |
I believe I am seeing this issue.
With a scope, I can see that the calls to xfer2(), xfer() and writebytes() all generate proper signals on the MOSI line. I get the same result using I see that the call to writebytes() generates a signal on MOSI that loops back to MISO. I expect that the data on MISO is then read into a hardware or software buffer and that readbytes() would convey the data from that buffer. Is this expectation wrong? If there are instructions on how to build and install this module, please share and I'll retry using the latest source. Other tidbit. I can call readbytes() with any reasonable non-zero value (1..512) and I get in return a list of that many zeros. I can call readbytes(100) repeatedly and get many 100-length lists of zeros, but there was no traffic on the SPI bus. I would expect some error reading from an empty queue. |
I just did the same check, with a loopback line between MOSI and MISO and got the same result for readbytes. xfer replicates the input as expected, but not writebytes/readbytes. |
I have more info on this, I played with the SPI driver more on Raspberry, the issue is originating from the driver itself. I wrote some C code that does something similar as the python lib and it seems that it's not the library's fault, it's the way the driver works. |
I believe that In other words, you'd need to have an external device, at least to act as a buffer, in order to test this properly. I believe this is not a bug, but an implementation/testing error. |
To provide some more explanation, I believe that |
It seems to be an issue on the second SPI bus on the pi4 using spidev. This code fails from spidev import * while the other three combinations of BUS= 0/1 and xfer/writebytes work. My /boot/config.txt includes dtparam=spi=on |
Please ignore my last (too hasty) comment. I was correct with the observation that it's spi1 related, but not in my diagnosis. It seems to be an interaction between spi mode and the bus. On my system, both writebytes and xfer fail with xfer reporting #Fails for both xfer and writebytes for BUS = 1 and MODE = 1, works for other from spidev import * BUS = 1 spi = SpiDev(BUS,0) Since this is not the problem reported, (differing behavior of xfer and either readbytes or writebytes), it may have nothing to do with the reported problem. Sorry for any confusion caused. |
I connected MISO and MOSI on my RaspberryPI and ran this program:
The array b should be echoed, but instead there are only zeroes. I checked writebytes() with an oscilloscope and it seems like it doesn't send anything at all.
But xfer and xfer2 work.
Or have I misunderstood writebytes? I thought it doesn't return anything, but keeps the data in a buffer which is accessable via readbytes.
some other interesting stuff:
The text was updated successfully, but these errors were encountered: