Description
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
#include <SPI.h>
void setup() {
// put your setup code here, to run once:
SPI.begin();
}
void loop() {
// put your main code here, to run repeatedly:
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
SPI.transfer(0x053);
SPI.endTransaction();
delayMicroseconds(1);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));
SPI.transfer(0x053);
SPI.endTransaction();
delayMicroseconds(1);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE2));
SPI.transfer(0x053);
SPI.endTransaction();
delayMicroseconds(1);
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
SPI.transfer(0x053);
SPI.endTransaction();
delayMicroseconds(16*8);
}
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:
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.