Wemos s2 mini spi - esp32-s2 spi issue?

I am trying to get the WEMOS S2 MINI to drive a TFT and have run into some basic problems with the SPI.
This board uses an ESP32-S2 with 4MB FLASH and 2MB PSRAM.
I am using ESP32 board core 2.0.1-RC1 and Arduino 1.8.15
The program below produces a 20MHz 3.3V clock on pin 36 but the MOSI data on pin 35 is only about 1V peak to peak. I am measuring this with a 200MHz Rigol scope.
When I just toggle pin 35 in a loop as a regular output I get a full 3.3V square wave as expected. So the problem appears to be something with the SPI setup.
VDD_SPI measures at 3.3V. I have tried this on several of these S2 Mini boards and the SPI CLK is there but MOSI is not or very low,
I have tried the clock at 1MHz, 20MHz and 40MHz and get the same thing. Clock looks fine, MOSI is low voltage or not there.
Any suggestions would be appreciated. Thanks, Bill

#include "SPI.h"
//See
//https://stackoverflow.com/questions/69101743/how-to-use-custom-pins-for-spi-on-esp32-pico-v3-02
SPIClass spi2(FSPI);
#define FSPI_MISO   37
#define FSPI_MOSI   35
#define FSPI_SCLK   36
#define FSPI_SS     34

static const int spiClk = 20000000; // 20 MHz
void setup() {
  // put your setup code here, to run once:
spi2.begin(FSPI_SCLK, FSPI_MISO, FSPI_MOSI, FSPI_SS);

}

void loop() {
uint8_t buf[100],i;
    for(i = 0; i < 100; i++)
        buf[i] = i;
    spi2.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE3));
    while(1){
    spi2.transfer(buf,100);
    delay(5);
    }
}
1 Like

Your post was MOVED to its current location as it is more suitable





I thought I would add some images to show what I am seeing on the ESP32-S2 WEMOS S2 MINI SPI lines. Note the 1V MOSI SIGNAL and the 3.3V SCLK. I did add a 10K pull-up on the MOSI GPIO and it did not change the signal.

I wrote a second program to try to show the MOSI and digitalWrite on the same GPIO 35 on the same scope shot. The program, in a loop, initiates the spi, starts a transaction, writes out the data, ends the transaction and releases the SPI. Then it sets up GPIO 35 and toggles it ON and OFF 4 times. You can see the jump from 1V on the MOSI to 3.3V on the digitalWrite. There is another level of weirdness going on. It appears the SPI MOSI sometimes ends low, sometimes high. When it ends high, the digitalWrite low only goes down to 1V. I don't know why. Any guesses or suggestions would be appreciated. Here is the webpage for the WEMOS S2 Mini:
https://www.wemos.cc/en/latest/s2/s2_mini.html
Here is the complete program:

#include "FS.h"
#include "SD.h"
#include "SPI.h"
//See
//https://stackoverflow.com/questions/69101743/how-to-use-custom-pins-for-spi-on-esp32-pico-v3-02
//https://github.com/espressif/esp-idf/blob/v4.2.1/examples/peripherals/spi_master/lcd/main/spi_master_example_main.c
//spi2_host
SPIClass spi2(HSPI);
#define FSPI_MISO   37
#define FSPI_MOSI   35
#define FSPI_SCLK   36
#define FSPI_SS     34

//https://github.com/espressif/arduino-esp32/issues/4716
//SPIClass spi2(HSPI);
//#define SD_miso  17
//#define SD_mosi  16
//#define SD_sck   15
//#define SD_ss    14
 
static const int spiClk = 20000000; // 1 MHz
void setup() {
  // put your setup code here, to run once:

  //spi2.begin(SD_sck, SD_miso, SD_mosi, -1);
   //pinMode(SD_ss, OUTPUT);
}

void loop() {
uint8_t buf[100],i;
    for(i = 0; i < 100; i++)
        buf[i] = i;

    while(1){
    spi2.begin(FSPI_SCLK, FSPI_MISO, FSPI_MOSI, FSPI_SS);
    spi2.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE3));
    spi2.transfer(buf,100);
    spi2.endTransaction();
    spi2.end();
    //spi2.end();
pinMode(FSPI_MOSI, OUTPUT);
digitalWrite(FSPI_MOSI,HIGH); 
digitalWrite(FSPI_MOSI,LOW);   
digitalWrite(FSPI_MOSI,HIGH);
digitalWrite(FSPI_MOSI,LOW);
digitalWrite(FSPI_MOSI,HIGH); 
digitalWrite(FSPI_MOSI,LOW);
digitalWrite(FSPI_MOSI,HIGH); 
digitalWrite(FSPI_MOSI,LOW);  
delay(5);
    }
}

I'm having the same problem with the SPI, I tried with a rfid module RC522 without results. Any suggestion will be appreciated.

Yes, I did get it working finally but I don't quite remember what the issue was. I will try to get back to you today after I look thru my notes. I absolutely did get it driving an SPI based LCD.

thanks a lot... I appreciate your help.

In my definition file for the SPI LCD, I have this code:
// FSPI port will be used unless the following is defined
//#define USE_HSPI_PORT

#define TFT_CS 34 // 10 or 34
#define TFT_MOSI 35 // 11 or 35
#define TFT_SCLK 36 // 12 or 36
#define TFT_MISO 37 // 13 or 37
#define TFT_DC 38

Those are the pin assignments I used and it looks like I chose FSPI over HSPI. I hope this helps. Let me know either way.

I've not used a S2 yet.

Here is the API, API Reference - ESP32-S2 - — ESP-IDF Programming Guide latest documentation (espressif.com)

SPI0 and SPI1 are used internally to access the ESP32-S2’s attached flash memory. Both controllers share the same SPI bus signals, and there is an arbiter to determine which can access the bus.

  • SPI2 and SPI3 are general purpose SPI controllers. They are open to users. SPI2 and SPI3 have independent signal buses with the same respective names. SPI2 has 6 CS lines. SPI3 has 3 CS lines. Each CS line can be used to drive one SPI slave.

It looks like you want to use SPI2 or SPI3.

Anyways, good luck.

I will ask your help another time sorry in advance, I have a sketch perfect working with a normal esp32 defining this pins :

#define RST_PIN         22  
#define SS_PIN          5         
#include <SPI.h>
#include <MFRC522.h>
MFRC522 mfrc522(SS_PIN, RST_PIN);

And I connected it in that way:

ESP32------------RC522
3v------------------3v
22 (SCL)---------RST
GND--------------GND
19(MISO)--------MISO
37(MOSI)--------MOSI
18 (SCK)---------SCK
5(SS)--------------SDA

I add to divide the post in 2 parts because as a new user i can't post 2 multimedia file in one post....

I modified the sketch for the S2 mini defining this pins:

#define CS 34 // 10 or 34
#define MOSI 35 // 11 or 35
#define SCLK 36 // 12 or 36
#define MISO 37 // 13 or 37
#define RST_PIN 9  
#define SS_PIN 7   

#include <SPI.h>
#include <MFRC522.h>
MFRC522 mfrc522(SS_PIN, RST_PIN);

And I connected it in that way:

... but it's not working, am I too stupid? can someone suggest me where is my mistake?

thanks

1 Like

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