Hi there,
So this is Running on the C3 and should also run on the S3
Try it and report back, It’s the Busses sketch modified, There’s lots of good info in there, so look it over.
/* The ESP32 has four SPi buses, however as of right now only two of
* them are available to use, HSPI and VSPI. Simply using the SPI API
* as illustrated in Arduino examples will use VSPI, leaving HSPI unused.
*
* However if we simply intialise two instance of the SPI class for both
* of these buses both can be used. However when just using these the Arduino
* way only will actually be outputting at a time.
*
* Logic analyser capture is in the same folder as this example as
* "multiple_bus_output.png"
*
* created 30/04/2018 by Alistair Symonds
*/
//#include <SPI.h>
#include <SPIMemory.h>
uint8_t pageBuffer[256];
String serialCommand;
char printBuffer[128];
uint32_t addr;
uint8_t dataByte;
uint16_t dataInt;
String inputString, outputString;
// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus
//#define ALTERNATE_PINS
#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
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define VSPI FSPI
#endif
#define VSPI FSPI
static const int spiClk = 1000000; // 1 MHz
//uninitalised pointers to SPI objects
SPIClass * fspi = NULL;
SPIClass * hspi = NULL;
#define SS 3
//SPIFlash flash;
SPIFlash flash(SS, &SPI); //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus
void setup() {
Serial.begin(9600);
while (!Serial) delay(2100);
Serial.println();
Serial.println(" Program " __FILE__ " compiled on " __DATE__ " at " __TIME__ );
Serial.println("----RESET----");
Serial.print(F("Initialising"));
for (uint8_t i = 0; i < 10; ++i)
{
Serial.print(F("."));
}
Serial.println();
//initialise two instances of the SPIClass attached to VSPI and HSPI respectively
fspi = new SPIClass(FSPI);
hspi = new SPIClass(HSPI);
//clock miso mosi ss
#ifndef ALTERNATE_PINS
//initialise vspi with default pins
//SCLK = 18, MISO = 19, MOSI = 23, SS = 5
fspi->begin();
#else
//alternatively route through GPIO pins of your choice
fspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
#endif
#ifndef ALTERNATE_PINS
//initialise hspi with default pins
//SCLK = 14, MISO = 12, MOSI = 13, SS = 15
hspi->begin();
#else
//alternatively route through GPIO pins
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS); //SCLK, MISO, MOSI, SS
#endif
//set up slave select pins as outputs as the Arduino API
//doesn't handle automatically pulling SS low
pinMode(fspi->pinSS(), OUTPUT); //VSPI SS
pinMode(hspi->pinSS(), OUTPUT); //HSPI SS
digitalWrite(SS, LOW); // <-- Set CS pin HIGH to deselect
Serial.println (VSPI_SS);
Serial.println (VSPI_MOSI);
Serial.println (VSPI_MISO);
Serial.println (VSPI_SCLK);
Serial.println();
Serial.println (HSPI_SS);
Serial.println (HSPI_MOSI);
Serial.println (HSPI_MISO);
Serial.println (HSPI_SCLK);
pinMode(SS, OUTPUT);
Serial.println();
digitalWrite(SS, LOW); // <-- Set CS pin HIGH to deselect
Serial.print("MOSI:");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
//digitalWrite(VSPI_SS,LOW);
flash.begin();
//Serial.print(F("Flash size: "));
// Serial.print((long)(flash.getCapacity()/1000));
// Serial.println(F("Kb"));
//digitalWrite(spi->pinSS(), HIGH); //pull ss high to signify end of data transfer
//spi->endTransaction();
//digitalWrite(SS, HIGH); // <-- Set CS pin HIGH to deselect
//digitalWrite(VSPI_SS,HIGH);
//flash.setClock(12000000); // uncomment here for Arduino SAMD boards
printLine();
printLine();
uint8_t b1, b2, b3;
uint32_t JEDEC = flash.getJEDECID();
//uint16_t ManID = flash.getManID();
b1 = (JEDEC >> 16);
b2 = (JEDEC >> 8);
b3 = (JEDEC >> 0);
clearprintBuffer();
sprintf(printBuffer, "Manufacturer ID: %02xh\nMemory Type: %02xh\nCapacity: %02xh", b1, b2, b3);
Serial.println(printBuffer);
clearprintBuffer();
sprintf(printBuffer, "JEDEC ID: %04xh", JEDEC);
Serial.println(printBuffer);
printLine();
//printNextCMD();
}
// the loop function runs over and over again until power down or reset
void loop() {
//use the SPI buses
//spiCommand(fspi, 0b01010101); // junk data to illustrate usage
//spiCommand(hspi, 0b11001100);
delay(1000);
}
void spiCommand(SPIClass *spi, byte data) {
//use it as you would the regular arduino SPI API
spi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(spi->pinSS(), LOW); //pull SS slow to prep other end for transfer
spi->transfer(data);
digitalWrite(spi->pinSS(), HIGH); //pull ss high to signify end of data transfer
spi->endTransaction();
}
void printLine()
{
Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------"));
}
void clearprintBuffer()
{
for (uint8_t i = 0; i < 128; i++) {
printBuffer[i] = 0;
}
}
Here is the output that is expected.
Program D:\Arduino_projects\SPI_Multiple_Buses\SPI_Multiple_Buses.ino compiled on Jan 25 2024 at 10:24:38
----RESET----
Initialising..........
3
10
9
8
15
13
12
14
MOSI:10
MISO: 9
SCK: 8
SS: 3
----------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------
Manufacturer ID: efh
Memory Type: 40h
Capacity: 14h
JEDEC ID: ef4014h
----------------------------------------------------------------------------------------------------------------------------------
HTH
GL PJ
ALso for a long shot can you set the CS pin to pin 7(which is GPIO44)
try that fist with no other pin defines , then try with the others(correct ones) defined 8,9,10.
LMK