Main Menu

search

You are here

WT32-SC01 SPI

[last updated: 2024-08-19]
WT32-SC01 display
https://randomnerdtutorials.com/esp32-spi-communication-arduino/
-----

Editing in process ... fumbling here ...

This is my process for using the WT32-SC01 to communicate via SPI with a Nano or Teensy Arduino.

  • The ESP32 has two usable SPI ports:
      HSPI (SPI2)
      VSPI (SPI3)

    Each of these buses can drive up to 3 peripherals.

  • In this module, the ESP32 communicates with the SC01 touch screen via SPI
      In the installation process, I had to edit the TFT userSetup.h, and in doing so, specified:
        "TFT_MOSI = 13", "TFT_MISO = 12", "TFT_SCLK = 14", and "TFT_CS = 15".
        These pins are un-labeled (ie. not identified as being any particular signal line) on the SC01 pcb connector...
  • ---------------------------------------------------------------------------

  • Per a bunch of online resosurces:
    • I found a table, that gives a number code to the two SPI buses (HSPI & VSPI),
      depending on which flavor of ESP32 MCU you were using.
        Model         HSPI     VSPI
        ESP32           1         3
        ESP32-S2     2          3
        ESP32-S3     2         3
        ESP32-C3     1         3

      My WT32-SC01 uses a ESP32-WRover-B, which I'm guessing at the moment is the "generic" ESP32 (S1)

        #define HSPI 1 // 2 for S2 and S3, 1 for S1
    • Define output pins:
        const int HSPI_MISO = 12;
        const int HSPI_MOSI = 13;
        const int HSPI_SCLK = 14;
        const int HSPI_CS = 15;
    • Don't understand this line, but it was in the example, so...
        SPIClass hspi = SPIClass(HSPI);
    • For message management:
        byte response = 0;
    • In setup:
        [pinModes presumably set in the library...]
        hspi.begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_CS);
        digitalWrite(HSPI_CS, HIGH); // initialize as inactive
    • In loop:
      To initiate a data transfer from this master to a slave:
        digitalWrite(HSPI_CS, LOW); // low active
        ... do the transfer ...
        digitalWrite(HSPI_CS, HIGH); // release/deactivate CS line
        ... retrieve the response from the slave and process it as desired ...

      -----------------------------------------

    • However:
      • Interfacing this to a nano slave is a problem,
        because the nano is 5v and the ESP only 3.3.
      • Since the ESP is the master, this will not be a problem for the MOSI, SCK, and CS lines,
        which send signals from ESP to nano, and even 3v will trigger the nano inputs,
      • but the MISO line will be sending 5v from the nano to the 3.3v-max-voltage inputs of the ESP,
        which may likely damage them.
      • SO: a level shift circuit will be needed on that line...

    eof