ESP32 S3 MINI SPI Pins

James_7122
Posts: 4
Joined: Tue Dec 12, 2023 10:29 am

ESP32 S3 MINI SPI Pins

Postby James_7122 » Tue Dec 12, 2023 10:41 am

Hi, I have a custom PCB with the S3 Mini and an EEPROM chip (very basic schematics for your reference). The code (modified from a git repo I found, also attached) worked with a Wrover Dev kit + breadboard, but for the PCB, EEPROM read operations always give "0" even after writing (see the two sections in loop()). I am wondering if I have misinterpreted how GPIO can be mapped to SPI bus.

I am using MATLAB to send serial data for writing to EEPROM. MATLAB confirms the serial response, but it seems that the writing operation is not working.

Thanks!
Attachments
schematic.png
schematic.png (43.14 KiB) Viewed 61684 times
spieeprom.h
(1.11 KiB) Downloaded 4108 times
spieeprom.cpp
(2.65 KiB) Downloaded 3987 times

lbernstone
Posts: 831
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 S3 MINI SPI Pins

Postby lbernstone » Wed Dec 13, 2023 3:34 pm

If you are able to send a command to the eeprom, and get a response, then it seems like your electrical connections are good.
Turn on verbose debugging and make sure you see a response from the eeprom device.
Does it work if you write to flash/nvs instead of the eeprom?
The only pin mapping issues that I can see is that you are using the USB pins for the SPI. However, as long as you don't enable usb at all, that should only have an effect at boot.

James_7122
Posts: 4
Joined: Tue Dec 12, 2023 10:29 am

Re: ESP32 S3 MINI SPI Pins

Postby James_7122 » Thu Dec 14, 2023 1:57 pm

Thanks so much for the reply. Being new to ESP32 programming in Arduino, I have tried very hard to enable verbose logging, referencing this link (https://esp32.com/viewtopic.php?t=5730) but I have had no luck (INO below). Am I missing something?

I tried adding the following to my SPI setup:

Code: Select all

	mySPI->begin(36, 37, 35, SS);
	SPISettings s;
	mySPI->beginTransaction(s);
I am puzzled by the fact that none of these functions (SPI-begin, SPI-transfer, SPI->set*) returns any kind of error code. SPI->transfer returns 0 no matter what pins I map in the setup, so I don't think the communication is actually happening.

The following code prints nothing:

Code: Select all

#if (!PLATFORMIO)
  // Enable Arduino-ESP32 logging in Arduino IDE
  #ifdef CORE_DEBUG_LEVEL
    #undef CORE_DEBUG_LEVEL
  #endif
  #ifdef LOG_LOCAL_LEVEL
    #undef LOG_LOCAL_LEVEL
  #endif

  #define CORE_DEBUG_LEVEL 5
  #define LOG_LOCAL_LEVEL CORE_DEBUG_LEVEL
#endif  

#include <esp32-hal-log.h>

#include <SPI.h>
#include <spieeprom.h>
#include "esp_log.h"

#define CHIP_SELECT 20
byte buffer[64];
uint16_t address = 0;
SPIClass Sonic_EEPROM_SPI = SPIClass(HSPI);

#define DEBUG

static const char* TAG = "main-main";

SPIEEPROM myEEPROM(EEPROM_TYPE_16BIT, CHIP_SELECT, &Sonic_EEPROM_SPI); // parameter is type
                    // type=0: 16-bits address
                    // type=1: 24-bits address
                    // type>1: defaults to type 0


void setup() {
  // delay(2000);

	Serial.begin(921600);

	myEEPROM.setup(); // setup myEEPROM

  while(Serial.available()>0)
    Serial.read();

  esp_log_level_set("*", ESP_LOG_VERBOSE);

  Serial.printf("LOG_LOCAL_LEVEL %d\n", LOG_LOCAL_LEVEL);
  //                                   esp32-hal-log.h            esp_log.h
  //                       level 0 = ARDUHAL_LOG_LEVEL_NONE    = ESP_LOG_NONE 
  ESP_LOGE(TAG, "ESP_LOGE, level 1 = ARDUHAL_LOG_LEVEL_ERROR   = ESP_LOG_ERROR");
  ESP_LOGW(TAG, "ESP_LOGW, level 2 = ARDUHAL_LOG_LEVEL_WARN    = ESP_LOG_WARN");    
  ESP_LOGI(TAG, "ESP_LOGI, level 3 = ARDUHAL_LOG_LEVEL_INFO    = ESP_LOG_INFO");
  ESP_LOGD(TAG, "ESP_LOGD, level 4 = ARDUHAL_LOG_LEVEL_DEBUG   = ESP_LOG_DEBUG");
  ESP_LOGV(TAG, "ESP_LOGV, level 5 = ARDUHAL_LOG_LEVEL_VERBOSE = ESP_LOG_VERBOSE");
}
[/code]

lbernstone
Posts: 831
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 S3 MINI SPI Pins

Postby lbernstone » Thu Dec 14, 2023 2:11 pm

https://docs.platformio.org/en/latest/p ... ebug-level
The SPI functions are void (Arduino spec?), but the underlying function calls should give you errors in verbose logging.

James_7122
Posts: 4
Joined: Tue Dec 12, 2023 10:29 am

Re: ESP32 S3 MINI SPI Pins

Postby James_7122 » Thu Dec 14, 2023 2:29 pm

EDIT: I managed to get verbose debugging, and the logs in setup() above actually go to the serial monitor now. SPI->transfer definitely doesn't create any logs that I can see

James_7122
Posts: 4
Joined: Tue Dec 12, 2023 10:29 am

Re: ESP32 S3 MINI SPI Pins

Postby James_7122 » Fri Dec 15, 2023 7:03 am

Now it's getting very strange. I wanted to test the pins themselves, so I used the following "blinky" code and tested with a multimeter. Pin 36 fluctuates between 3.3V and 2.4V, and pin 37 fluctuates between 0.5V and 0.8V, and pin 35 correctly fluctuates between 3.3 and 0. Why could this be?

Code: Select all



void setup() {
  pinMode(36, OUTPUT);
  pinMode(37, OUTPUT);
  pinMode(35, OUTPUT);
}

void loop() {

digitalWrite(35, LOW); 
digitalWrite(36, LOW); 
digitalWrite(37, LOW); 
delay(2000);

digitalWrite(35, HIGH); 
digitalWrite(36, HIGH); 
digitalWrite(37, HIGH); 
delay(2000);

}

lbernstone
Posts: 831
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 S3 MINI SPI Pins

Postby lbernstone » Fri Dec 15, 2023 4:00 pm

This sounds like normal operation for an SPI bus. If there is a lot of variability of the voltage level, that could imply you don't have enough capacitance and filtering on the devices. Look at the datasheets and design guides for the eeprom and esp32 to get appropriate values for capacitance, and you should almost always have a 100nF filter on the input to digital devices.
The correct tool for troubleshooting this is a logic analyzer, where you can see the conversation happening b/w the devices. Again, I ask, does this work if you write to flash. Why are you using an eeprom when you have megabytes on board the esp32.

Who is online

Users browsing this forum: lbernstone and 69 guests