SPI on ESP32 doesnt get data

I have two Esp32S3 boards, and I want to establish Spi communication between them. I have a couple of questions:

  1. Why can't I see the clock signal using the logger?
  2. Why can't I receive the data?
#include <SPI.h>

#define MOSI_PIN 10 
#define MISO_PIN 9  
#define SCK_PIN  8  
#define SS_PIN   5  

SPIClass hspi;

void setup() {
  Serial.begin(115200);

  delay(1000);

  hspi.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN); 

  pinMode(SS_PIN, OUTPUT);
  
  digitalWrite(SS_PIN, HIGH); 
}

void loop() {
  
  Serial.println("L Start..");
  digitalWrite(SS_PIN, LOW); 
  
  hspi.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
  
  hspi.transfer(0xFA); 
  
  hspi.endTransaction();
  
  digitalWrite(SS_PIN, HIGH); 
  delay(1000); 

}
#include <SPI.h>

#define MOSI_PIN 10 
#define MISO_PIN 9
#define SCK_PIN  8
#define SS_PIN   5

void setup() {
  Serial.begin(115200);
  pinMode(SS_PIN, INPUT_PULLUP); 

  SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
}

void loop() {

  if (digitalRead(SS_PIN) == HIGH) 
  { 
    byte receivedData = SPI.transfer(0x00);
    Serial.print("Data Received: ");
    Serial.println(receivedData, HEX); 
  }

}

Ive never done it myself but i believe theres an spi.attachslave method

SPI works in a master slave idea. 1 master, many slaves

Im assuming running 2 masters your clock signals will be colliding.

Well the pins you are trying to use for SPI are also used for the flash, you can't use those pins.

#define MOSI_PIN 10 
#define MISO_PIN 9  
#define SCK_PIN  8  

Try different pins, and also you method for using hspi is not correct.
either use a global pointer

SPIClass * hspi = NULL;

setup() {
hspi = new SPIClass(HSPI);
hspi->begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
}

or define which SPI to use when declaring

SPIClass hspi(HSPI);

setup() {
  hspi.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN); 
}

But mainly, use different pins, not 6 - 11 and i found even pins 12 & 13 to be problematic.

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