hideakitai / ESP32SPISlave

SPI Slave library for ESP32
MIT License
51 stars 15 forks source link

Crash while using WiFi #48

Open SwapnilPande opened 9 hours ago

SwapnilPande commented 9 hours ago

Hello!

I've been trying to setup an ESP32-S3 as an SPI Slave while using WiFi with a Raspberry Pi as the master. I am able to get stable communications at 5 MHz with WiFi disable. However, the driver seems to crash if I try to enable WiFi as well. I have tried to use DMA/non-DMA, different SPI modes with no success. The only thing that seems to improve the stability is dropping the SPI clock frequency significantly (500 Hz).

I will try to provide a minimal working example soon. Do you have thoughts as to what might be causing this?

SwapnilPande commented 9 hours ago
#include <ESP32SPISlave.h>
#include <WiFi.h>

#define MOSI 35
#define MISO 48
#define SCK 47
#define SS 21

uint8_t tx_buf[64]{0};
uint8_t rx_buf[64]{0};

ESP32SPISlave slave;

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

  delay(4000);

  // Connect to Wi-Fi
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.println("Connecting to WiFi...");
  }

  Serial.println("Connected to WiFi");

  slave.setDataMode(SPI_MODE3);  // default: SPI_MODE0
  slave.setQueueSize(1);         // default: 1

  slave.begin(FSPI, SCK, MISO, MOSI, SS);
}

void loop()
{
  //   Allocate buffers
  const size_t received_bytes = slave.transfer(tx_buf, rx_buf, 64, 50);
}

Here is the minimum example

hideakitai commented 8 hours ago

The driver and the program work fine if it works with a lower frequency. I suspect the increased power consumption by WiFi causes the noise on the SPI lines. The noise prevents the higher frequency. Could you take a look at the SPI line waveforms?