Connecting SPI FLASH to ESP32 HSPI fails

Hi,

I'm trying to connect SPI FLASH to ESP32 HSPI-port using SPIMemory.h library (v3.4.0) but can't get the sketch even compiled.

I'm using HSPI because I need to connect something else to VSPI later but for now I have only FLASH chip (Winbond W25Q64JV) connected to ESP32-WROVER module. The board selected from Arduino IDE is "ESP32 Wrover Module".

Wiring to FLASH chip is as:
MISO: IO12, WROVER pin# 14, HSPIQ
MOSI: IO13, WROVER pin# 16, HSPID
CLK: IO 14, WROVER pin# 13, HSPICLK
CS: IO15, WROVER pin# 23, HSPICS0
But I'm not even so far to see if the wiring is ok since the sketch is not compiling...

I'm trying with SPIMemory.h library example sketch "readWriteString.ino" with only modifications to define the use of SPI2 (HSPI).

Trying with sketch below with SPIFlash flash(csPin, &SPI2) I get error 'SPI2' was not declared in this scope.

#include<SPIMemory.h>

uint32_t strAddr;
const int csPin = 15;  //added

//int8_t SPIPinsArray[4] = {14, 12, 13, 15};  //added

#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
// Required for Serial on Zero based boards
#define Serial SERIAL_PORT_USBVIRTUAL
#endif

#if defined (SIMBLEE)
#define BAUD_RATE 250000
#define RANDPIN 1
#else
#define BAUD_RATE 115200
#define RANDPIN A0
#endif

SPIFlash flash(csPin, &SPI2);       //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus
//SPIFlash flash;      //orig
//SPIFlash flash (SPIPinsArray);   // containing the custom SPI pin numbers (as signed integers - int8_t) in the following order - sck, miso, mosi, ss.

bool readSerialStr(String &inputStr);

void setup() {
  Serial.begin(BAUD_RATE);
#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__)
  while (!Serial) ; // Wait for Serial monitor to open
#endif

  flash.begin();

  randomSeed(analogRead(RANDPIN));
  strAddr = random(0, flash.getCapacity());
  String inputString = "This is a test String";
  flash.writeStr(strAddr, inputString);
  Serial.print(F("Written string: "));
  Serial.println(inputString);
  Serial.print(F("To address: "));
  Serial.println(strAddr);
  String outputString = "";
  if (flash.readStr(strAddr, outputString)) {
    Serial.print(F("Read string: "));
    Serial.println(outputString);
    Serial.print(F("From address: "));
    Serial.println(strAddr);
  }
  while (!flash.eraseSector(strAddr));
}

void loop() {

}

//Reads a string from Serial
bool readSerialStr(String &inputStr) {
  if (!Serial)
    Serial.begin(115200);
  while (Serial.available()) {
    inputStr = Serial.readStringUntil('\n');
    Serial.println(inputStr);
    return true;
  }
  return false;
}

Based on SPIMemory.h documentation I thought SPI2 works like that...
So next I tried using array.

Trying with sketch below with SPIFlash flash (SPIPinsArray) I get error invalid conversion from 'int8_t*' {aka 'signed char*'} to 'uint8_t' {aka 'unsigned char'} [-fpermissive]

#include<SPIMemory.h>

uint32_t strAddr;
//const int csPin = 15;  //added

int8_t SPIPinsArray[4] = {14, 12, 13, 15};  //added

#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
// Required for Serial on Zero based boards
#define Serial SERIAL_PORT_USBVIRTUAL
#endif

#if defined (SIMBLEE)
#define BAUD_RATE 250000
#define RANDPIN 1
#else
#define BAUD_RATE 115200
#define RANDPIN A0
#endif

//SPIFlash flash(csPin, &SPI1);       //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus
//SPIFlash flash;      //orig
SPIFlash flash (SPIPinsArray);   // containing the custom SPI pin numbers (as signed integers - int8_t) in the following order - sck, miso, mosi, ss.

bool readSerialStr(String &inputStr);

void setup() {
  Serial.begin(BAUD_RATE);
#if defined (ARDUINO_SAMD_ZERO) || (__AVR_ATmega32U4__)
  while (!Serial) ; // Wait for Serial monitor to open
#endif

  flash.begin();

  randomSeed(analogRead(RANDPIN));
  strAddr = random(0, flash.getCapacity());
  String inputString = "This is a test String";
  flash.writeStr(strAddr, inputString);
  Serial.print(F("Written string: "));
  Serial.println(inputString);
  Serial.print(F("To address: "));
  Serial.println(strAddr);
  String outputString = "";
  if (flash.readStr(strAddr, outputString)) {
    Serial.print(F("Read string: "));
    Serial.println(outputString);
    Serial.print(F("From address: "));
    Serial.println(strAddr);
  }
  while (!flash.eraseSector(strAddr));
}

void loop() {

}

//Reads a string from Serial
bool readSerialStr(String &inputStr) {
  if (!Serial)
    Serial.begin(115200);
  while (Serial.available()) {
    inputStr = Serial.readStringUntil('\n');
    Serial.println(inputStr);
    return true;
  }
  return false;
}

Now running out of things to try since both of those above should have worked in my mind.
Any help on this appreciated...

Thanks,
Tipo

Hi, please, post lib SPIMemory.h link.

Thanks for following the forum guidelines in posting your code. Hint it will not work: Your wiring does not have power or ground per your list. Posting a schematic not a frizzy picture would be a big help and you would see missing connections.

SPIMemory.h (5.7 KB)

The file is attached here.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.