# SPI on ESP32 doesnt get data

**URL:** <https://forum.arduino.cc/t/spi-on-esp32-doesnt-get-data/1197126>\
**Category:** Programming\
**Created:** [December 5, 2023, 3:44pm UTC](https://forum.arduino.cc/t/spi-on-esp32-doesnt-get-data/1197126 "2023-12-05T15:44:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vergilooos](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/vergilooos/32/1021736_2.png) [@vergilooos](https://forum.arduino.cc/u/vergilooos)\
**Post date:** [December 5, 2023, 3:44pm UTC](https://forum.arduino.cc/t/spi-on-esp32-doesnt-get-data/1197126/1 "2023-12-05T15:44:12Z")

</div>

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?

```arduino
#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); 

}

```

```arduino
#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); 
  }

}

```

---

<div class="post-metadata">

**Author:** ![theboot](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/theboot/32/981094_2.png) [@theboot](https://forum.arduino.cc/u/theboot)\
**Post date:** [December 6, 2023, 5:16am UTC](https://forum.arduino.cc/t/spi-on-esp32-doesnt-get-data/1197126/2 "2023-12-06T05:16:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [December 6, 2023, 8:38am UTC](https://forum.arduino.cc/t/spi-on-esp32-doesnt-get-data/1197126/3 "2023-12-06T08:38:16Z")

</div>

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

```arduino
#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

```arduino
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

```arduino
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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 3, 2024, 8:39am UTC](https://forum.arduino.cc/t/spi-on-esp32-doesnt-get-data/1197126/4 "2024-06-03T08:39:05Z")

</div>

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