-
Notifications
You must be signed in to change notification settings - Fork 10
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
Bitbang SPI phase=1 lowest bit is wrong #20
Comments
Thanks for the report. A couple of questions:
The operative code is here, and looks OK to me on first glance: |
Hi Dan,
I first noticed this as I was driving a DDS chip. Using busio the DDS did not set to quite the right frequency. The LSBit is generally not a big impact but for the DDS it was the LSbit in the msb of the frequency set and set the frequency about 10% low over what it should have been. I was using the equivalent of the metro_m4_express. I then did a Busio version which worked OK with the same polarity/phase settings. I then tried the bitbang version on the QT PY which is the waveform that I included with the problem report. I tried both a 16 bit send and 2 eight bit sends. The two 8 bit sends dropped both LSbits. I am including the bitbang/SPI comparison waveforms.
[Inline image]
Regards,
Glen
|
Thanks, your inline image did not come through. Could you post directly in GitHub? [I edited your reply to remove the repetition of my post.] |
Hi Dan,
I am not well versed in Github unfortunately. One more thing to master. I posted the waveforms and programs on the Adafruit Forum under 'SPI Busio vs Bitbangio' on sept 3. It is under gingle in Adafruit Circuitpython and Micropython. The DDS was an AD9832.
Could you send any replies to ***@***.******@***.***>? I am doing most of my work at home and have my files on my home computer.
Thanks,
Glen
|
I just realized you are using the https://github.com/adafruit/Adafruit_CircuitPython_BitbangIO Python-based library ( |
We use GitHub so everyone can see the replies. When you get an email from GitHub, don't reply via mail, but instead click the "View it on GitHub" link in the email: That will bring you directly here so you can reply. |
Dan, you are correct. I verified the built in version of bitbangio as working correctly. the Adafruit version has the LSbit problem. |
Bonjour, I don't know if this is the best way to do things and if it could have side effects, I'm not an experienced developer. But for now this is a modification that works for me. PS sorry, for English via google translate, I read well but I speak English "like a Frenchman" ;-) |
in connection with adafruit#20 tested on max31856 (phase 1) and st7735R (phase 0) on a raspberry pico/u2if. Also solves the problem of a max31856 on raspberry pi (impossible to set the thresholds)
Please accept @Linkeor 's pull request as above! The MAX31956 does not work using BitbangIO without this fix. Some kiln-controller users (https://github.com/jbruce12000/kiln-controller) cannot upgrade their software without re-soldering as software pins will not work with this library on the '56. I have tested @Linkeor 's changes on an RPi 3+ with both the MAX31855 and '56. They work in all the expected cases, hardware pins / software SPI via BitbangIO, hardware pins / hardware SPI, software pins / BitbangIO. This change does not effect the MAX31855 but it seems to be needed for any board that uses MOSI. |
While writing some tests, I came across what might be a timing bug introduced by #30 This is the test code: with adafruit_bitbangio.SPI(clock=clock, MOSI=copi, MISO=cipo) as spi:
spi.try_lock()
spi.configure(baudrate=100, polarity=0, phase=0, bits=8)
echo.enable(True)
spi.write([0b10101011]) Prior to the change, as noted in the initial description here, there was a general offset problem where bits were pushed out one clock transition too late. However, each bit was still pushed on the data line at the right clock phase. Here is a sample trace before the fix. The first bit is set on the first falling clock, but the first rising clock has already been read by that time. So the peripheral effectively sees a right-rotated version of the data in this case. However, each bit is still pushed during the falling clock transition, it doesn't interfere with the read. However, after the fix the bits are set on rising clock transitions, when they are also read. Possibly many peripherals are still able to decode it as there's just enough delay between the data line being set and the clock being immediately transitioned in python land; but I'm not sure if this is ideal. (Happy to provide a fix if this seems worth correcting, as I noticed this while testing the protocol; rather than seeing issues in the wild.) |
CircuitPython version
Code/REPL
Behavior
Description
No response
Additional information
This works correctly:
from adafruit_bus_device.spi_device import SPIDevice
The text was updated successfully, but these errors were encountered: