For ESP32, unless the exact board variant is specified, by default the macros for MISO, MOSI, SCK and SS isare defined as the followingfollows and isare used for VSPI(i.e. SPI0):
static const uint8_t SS = 5; static const uint8_t MOSI = 23; static const uint8_t MISO = 19; static const uint8_t SCK = 18; This can be seen in the source code and HSPI is automatically configured to use SCLK 14, MISO 12, MOSI 13 and SS 15 when the SPI.begin() is called, see this part of the source code.
Since you defined the HSPI_SSHSPI_SS as #define HSPI_SS SS, so when you are doingdo pinMode(HSPI_SS, OUTPUT);, you are actually setting the pin 5 as output, not the pin 15 that you thought it was.
There are two ways to properly setupset up the HSPI port.
- What you can do is to define the macros as followingfollows and calling thecall
hspi->begin();by passing your configuration:
#define HSPI_MISO 12 #define HSPI_MOSI 13 #define HSPI_SCLK 14 #define HSPI_SS 15 void setup() { hspi = new SPIClass(HSPI); hspi->begin(HSPI_SCK, HSPI_MISO, HSPI_MOSI, HSPI_SS); // rest of your setup code } - As you can see from the source code shown in the above link, if you don't explicitly passingpass the pins as parameters when calling
SPI.begin(), the library will automatically assign the pins based on whether whether VSPI is used (SCLK 18, MISO 19, MOSI 23, SS 5), or HSPI is used (SCLK 14, MISO 12, MOSI 13 and SS 15), so. So all you need to define is your HSPI_SSHSPI_SSpin:
#define HSPI_SS 15 void setup() { hspi = new SPIClass(HSPI); hspi->begin(); // rest of your setup code }