-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
SPI Library: SPI Mode 2 and 3 are wrong #2416
Comments
I suggest the following change in SPI.cpp:
not yet tested... |
Sorry for outright bumping this, but I ran into this issue just now. I was trying to use an ST7920 LCD with the u8g2 library, which requires SPI mode 3. Since this breaks portability, I advocate merging #2418. I have also made some measurements with my hantek 6022BE and pulseview, see attached: |
@igrr The referenced code looks unchanged in latest git, so this bug seems to still be valid. However, I don't know enough about SPI, nor about the ESP's internal registers, nor about the other Arduino boards, to evaluate. |
I have an arduino nano lying around somewhere, but i won't be able to test anything and compare until late next week. If someone else can have a look at this and check, that would be great. |
If it helps at all, the file For reference, I was using version 2.3.0 from the board manager for those measurements. |
Also reported in #2270 . |
I'm the reporter of #2270 and I confirm I also encountered this weirdness with SPI modes more than one year ago while working on SPI slave with the help of @me-no-dev . |
This is all explained in the ESP32 techincal manual: https://www.openhacks.com/uploadsproductos/esp32_technical_reference_manual_en_qg.pdf. The ESP32 seems to have almost the same SPI module as the ESP8266. That manual shows on page 118 that SPI_CK_OUT_EDGE should be set for modes 1 and 2, so it isn't the same as CPHA. It also documents bit 29 of the pin register as SPI_CK_IDLE_EDGE, which is the same as CPOL. |
@igrr @vicnevicne what about this issue? As @olikraus mentioned there is a potentially simple fix. |
From #2418:
I don't know the implications of the contra point. What can be done is either
|
@d-a-v doesn't matter which one will be added, the important thing is that it will be fixed. |
It is simply wrong and should be fixed. No reason to add a new function for the buggy old behaviour because it is trivial to fix code that relies on the bug. How would that ever have arisen anyway? Trial and error programming? The first person to use these modes should have noticed the bug. |
(.. and used a workaround) The "contra" is the reason why this 3years old issue with no possible smooth transition is still not merged. edit #2418 cannot be merged, github doesn't show the merge neither the update button probably because the PR is too old. |
First: Thanks a lot for the ESP8266 board package for the Arduino IDE. Great Work.
Basic Infos
Hardware
Hardware: Adafruit Feather HUZZAH ESP 8266
Core Version: Boardpackage 2.3.0
Description
Problem description
SPI Mode 2 and 3 are swapped compared to other boards like Uno, Due and 101.
A .ino file written for the Due, which uses SPI Mode 2 or 3 will not work on the ESP8266.
Settings in IDE
Module: Generic ESP8266 Module
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: ?
Flash Frequency: ?
Upload Using: USB Serial
Reset Method: ?
Sketch
Debug Messages
This picture shows the current (wrong) behavior.
The byte 0x053 is written in all four modes: From left to right mode 0, 1, 2 and 3. The last two transmitts are wrong. See below of correct output.
See also here: http://forum.arduino.cc/index.php?topic=419660.0
The common behavior is this for the Due:
Or this for the Uno:
BTW: I have seen that this is marked as a todo in the code for this project: Arduino/libraries/SPI/SPI.cpp
Thanks for fixing this.
The text was updated successfully, but these errors were encountered: