Page 1 of 1

How to select between multiple HW SPI peripherals

Posted: Wed Sep 01, 2021 8:23 am
by zazas321
Hello. I have checked multiple ESP32 arduino platform examples for SPI devices such as LIS3DH accelerometer, SSD1306 oled display and I cannot understand one thing. Whenever the HW SPI is initialised, it defaults to pins GPIO23(MOSI), GPIO19(MISO), GPIO18(SCLK). Since ESP32 has multiple HW SPI peripherals, what if I have wired my SPI to another HW SPI peripheral GPIO13(MOSI), GPIO12(MISO), GPIO14(SCLK). How can I change that?

Re: How to select between multiple HW SPI peripherals

Posted: Wed Sep 01, 2021 2:04 pm
by lbernstone
You will need to make a non-default SPI object and use that object to initialize your devices.

Code: Select all

SPIClass SD_SPI(VSPI);

void setup() {
    Serial.begin(115200);
    SD_SPI.begin(SD_SCK_PIN,SD_MISO_PIN,SD_MOSI_PIN,SD_CS_PIN);
    SD.begin(SD_CS_PIN,SD_SPI);
}