"Adafruit_SPIFlash.h" with ESP32 second SPI

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tipo1000
 
Posts: 7
Joined: Thu Aug 19, 2021 11:04 am

"Adafruit_SPIFlash.h" with ESP32 second SPI

Post by Tipo1000 »

Hi,

"Adafruit_SPIFlash.h" works fine with my ItsyBitsy internal 2MB FLASH. Now I want to use "Adafruit_SPIFlash.h" with external FLASH chip in second SPI of ESP32-WROVER. How do I define that I have FLASH chip connected to second SPI bus?

Connections are: CLK in GPIO14, MISO in GPIO12, MOSI in GPIO13 and CS in GPIO15. Those are from ESP32 specification.

Thanks,
Tipo

User avatar
adafruit_support_mike
 
Posts: 67459
Joined: Thu Feb 11, 2010 2:51 pm

Re: "Adafruit_SPIFlash.h" with ESP32 second SPI

Post by adafruit_support_mike »

The Adafruiit_SPIFlash class takes the SPI interface as an input parameter:

https://github.com/adafruit/Adafruit_SP ... mp.ino#L44

Create a Adafruit_FlashTransport_SPI object for the secondary SPI interface, then feed that to the Adafruiit_SPIFlash object when you create it.

User avatar
Tipo1000
 
Posts: 7
Joined: Thu Aug 19, 2021 11:04 am

Re: "Adafruit_SPIFlash.h" with ESP32 second SPI

Post by Tipo1000 »

Hi Mike,

I tried below, but got an error. I can't figure out how to create object for second SPI. Somehow I should define pins or 'port' I want to use but 'HSPI' nor 'SPI2' works. So how to define it?

Code: Select all

Adafruit_FlashTransport_HSPI flashTransport(15, HSPI); //HSPI pins: CLK - IO14, MISO - IO12, MOSI - IO13 and CS - IO15
//Adafruit_FlashTransport_VSPI flashTransport(5, VSPI); //VSPI pins: CLK - IO18, MISO - IO19, MOSI - IO23 and CS - IO5

Adafruit_SPIFlash flash(&flashTransport);

Code: Select all

"flash_sector_dump_example_test1:9:26: error: 'flashTransport' was not declared in this scope
 Adafruit_SPIFlash flash(&flashTransport);" and "'Adafruit_FlashTransport_HSPI' does not name a type; did you mean 'Adafruit_FlashTransport_SPI'?
Below gives basically same error:

Code: Select all

Adafruit_FlashTransport_HSPI flashTransport(15, SPI2); //HSPI pins: CLK - IO14, MISO - IO12, MOSI - IO13 and CS - IO15
//Adafruit_FlashTransport_VSPI flashTransport(5, VSPI); //VSPI pins: CLK - IO18, MISO - IO19, MOSI - IO23 and CS - IO5

Adafruit_SPIFlash flash(&flashTransport);

Code: Select all

flash_sector_dump_example_test1:9:26: error: 'flashTransport' was not declared in this scope
 Adafruit_SPIFlash flash(&flashTransport);
Adafruit_FlashTransport_HSPI' does not name a type; did you mean 'Adafruit_FlashTransport_SPI'?
Can I use those two SPI's in the same code? I would read from data from sensor in one SPI and write to FLASH in another SPI.

Thanks,
Tipo

User avatar
Tipo1000
 
Posts: 7
Joined: Thu Aug 19, 2021 11:04 am

Re: "Adafruit_SPIFlash.h" with ESP32 second SPI

Post by Tipo1000 »

Small addition to previous... I kind of understand how it's done below with "spi.h" and now trying to see how the same thing would be done with "Adafruit_SPIFlash.h":

Code: Select all

/ Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus

#ifdef ALTERNATE_PINS
  #define VSPI_MISO   2
  #define VSPI_MOSI   4
  #define VSPI_SCLK   0
  #define VSPI_SS     33

  #define HSPI_MISO   26
  #define HSPI_MOSI   27
  #define HSPI_SCLK   25
  #define HSPI_SS     32
#else
  #define VSPI_MISO   MISO
  #define VSPI_MOSI   MOSI
  #define VSPI_SCLK   SCK
  #define VSPI_SS     SS

  #define HSPI_MISO   12
  #define HSPI_MOSI   13
  #define HSPI_SCLK   14
  #define HSPI_SS     15
#endif
and is setup...

Code: Select all

void setup() {
  //initialise two instances of the SPIClass attached to VSPI and HSPI respectively
  vspi = new SPIClass(VSPI);
  hspi = new SPIClass(HSPI);
Complete example for spi.h is here: https://github.com/espressif/arduino-es ... _Buses.ino

Similar example would help a newbie like me :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”