Skip to main content
deleted 36 characters in body
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

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.

  1. 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 } 
  1. 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_SS pin:
#define HSPI_SS 15 void setup() { hspi = new SPIClass(HSPI); hspi->begin(); // rest of your setup code } 

For ESP32, unless the exact board variant is specified, by default the macros for MISO, MOSI, SCK and SS is defined as the following and is 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_SS as #define HSPI_SS SS, so when you are doing 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 setup the HSPI port.

  1. What you can do is to define the macros as following and calling the 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 } 
  1. As you can see from the source code shown in the above link, if you don't explicitly passing the pins as parameters when calling SPI.begin(), the library will automatically assign the pins based on 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 all you need to define is your HSPI_SS pin:
#define HSPI_SS 15 void setup() { hspi = new SPIClass(HSPI); hspi->begin(); // rest of your setup code } 

For ESP32, unless the exact board variant is specified, by default the macros for MISO, MOSI, SCK and SS are defined as follows and are 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 SPI.begin() is called, see this part of the source code.

Since you defined HSPI_SS as #define HSPI_SS SS, when you do pinMode(HSPI_SS, OUTPUT);, you are actually setting pin 5 as output, not the pin 15 that you thought it was.

There are two ways to properly set up the HSPI port.

  1. What you can do is to define the macros as follows and call 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 } 
  1. As you can see from the source code shown in the above link, if you don't explicitly pass the pins as parameters when calling SPI.begin(), the library will automatically assign the pins based on 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 all you need to define is your HSPI_SS pin:
#define HSPI_SS 15 void setup() { hspi = new SPIClass(HSPI); hspi->begin(); // rest of your setup code } 
Source Link
hcheung
  • 2k
  • 9
  • 16

For ESP32, unless the exact board variant is specified, by default the macros for MISO, MOSI, SCK and SS is defined as the following and is 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_SS as #define HSPI_SS SS, so when you are doing 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 setup the HSPI port.

  1. What you can do is to define the macros as following and calling the 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 } 
  1. As you can see from the source code shown in the above link, if you don't explicitly passing the pins as parameters when calling SPI.begin(), the library will automatically assign the pins based on 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 all you need to define is your HSPI_SS pin:
#define HSPI_SS 15 void setup() { hspi = new SPIClass(HSPI); hspi->begin(); // rest of your setup code }