Wifi Kit 32 V3 SPI Pinout / MicroSD Card Adapter Issues

Looking for some assistance on how to connect an SD Card adapter to the WifitKit 32 V3 board. I’m a bit of a beginner at this level but I’ve gone through all the ESP-IDF / ESP32 documentation and the 3/4 posts on this board with people having similar issues to no avail.

Adapter Board Reference:


Using 5V output from mainboard to power adapter.

Wifi Kit 32 V3 Pinout Reference: https://resource.heltec.cn/download/WiFi_Kit_32_V3/HTIT-WB32_V3.png

It looks like the SPI bus ( SCK, CS, MISO, MOSI ) pins are taken by the LoRa chip: https://resource.heltec.cn/download/WiFi_Kit_32_V3/HTIT-WB32_V3_Schematic_Diagram.pdf

My understanding is that any of the GPIO pins can be set to handle SD communications with the board. I’ve tried something like this and it failed:

#define SD_CS 2
#define SD_MISO 33
#define SD_MOSI 34
#define SD_SCK 26

SPIClass *hspi = NULL;

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

  hspi = new SPIClass(HSPI);
  hspi->begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);

  pinMode(SD_CS, OUTPUT);

  if(!SD.begin(SD_CS, *hspi)){
    Serial.println("Card Mount Failed");
    return;
  }else{
    Serial.println("Card Mounted");
  }
}

I then tried just updating the internal reference for those pins in the pins_arduino.h file for my board.
Then tried a simple task like this and it failed:

 Serial.begin(115200);
  while(!Serial);

  pinMode(SS, OUTPUT);

  if(!SD.begin(SS)){
    Serial.println("Card Mount Failed");
    return;
  }else{
    Serial.println("Card Mounted");
  }

Instead of compiling through Arduino IDE I tried ESP-IDF / idf.py menuconfig to see if there is a setting I need to toggle but found nothing.

I then spent a few hours trying as many combinations as I could. EG:
All digital pins 2,3,4,5
All pins listed as SPI I2c: 26, 33, 34, 35
Tried moving Chip Select to a digital so that MISO/MOSI/CLK were on SPI pins that weren’t connected: CS == 2, MISO/MOSI/CLK == 26, 33, 34
Tried the pins MTCK, MTDO, MTDI, MTMS and all the permutations there.

Nothing works and I am so confused as to why. Is it a wiring issue maybe or a software issue. Didn’t try VSPI but presume it would be the same issues. Can’t wait for it to be a super silly issue but any help would be appreciated.

FWIW:
Works flawlessly on Arduino UNO R3 so SD Card Adapter + Card are good.
Heltec BLE and OLED work great so I think the ESP32S3 is good too.

I’m not sure to read you well, but did you just change the pin for CS and NOTHING ELSE ?
Because it’s the best way to play with SPI for me :wink:

Thanks for the response!

I don’t follow. What pins do you recommend I use for CS, MISO, MOSI, CS?

In fact you must use same pins than the LoRa chip for SPI as you tell in your first message

It looks like the SPI bus ( SCK, CS, MISO, MOSI ) pins are taken by the LoRa chip

But for all pins EXCEPT CS that you have to put on another digital pin than the used by LoRa chip.

Is it clear like that ?

I see what you are saying but, those pins are 9, 10, 11: https://resource.heltec.cn/download/WiFi_Kit_32_V3/HTIT-WB32_V3_Schematic_Diagram.pdf

And are internal / there are no pinouts for them.

Oh shitty.

But you talk albout

And what are these pins if not related to SPI bus ?
And maybe check if you have a 1 on MTMS pin when you sending Lora data (and why not other signals, you should have ‘clock’ on MTCK, etc. ) .

Oh, did you see this post ?

That is what I thought too but it still isn’t working. Unfortunately, I can’t measure ‘clock’ as I don’t own an oscilloscope :cry:

Can confirm that Chip Select is toggling as desired.
I saw that post too and I tried using SDA and SCL pins for MISO/MOSI but that didn’t work either.

I wonder if this board doesn’t support multiple buses since LoRa uses one…

I am able to use a microsd card wired directly to the board, using a variety of pins. Not all configurations work, but if you start from a working configuration, you can move one pin at a time and usually find something that doesn’t conflict with other uses of the board. I have been able to use both SD card and LoRa, but you need to use two different SPI objects.

As a starting point, here’s a working V3 micro sd card setup:

#define SD_CS 36
#define SD_MOSI 34
#define SD_MISO 19
#define SD_SCLK 5

SPIClass sd_spi(HSPI);

void setup() {
    Serial.begin(115200);
    sd_spi.begin(SD_SCLK, SD_MISO, SD_MOSI, SD_CS);
    if (!SD.begin(SD_CS, sd_spi)) {
        Serial.println("Card Mount Failed");
        return;
    }

The rest of my sketch is copied from SD_Test.ino if you just want to validate if things are working.

The key to co-existing with LoRa is to define a new instance of SPIClass which can have different pins than the default global SPI object which is used by LoRa.

Note, it’s important that the SPIClass be defined globally. If you define the SPIClass inside a function, it will get freed when it goes out of scope and then your SD card won’t work.

Also maybe worth mentioning that I am using a micro sd card wired directly to the pins of the heltec V3 board. I am not using a step-down adapter board like the one pictured, but should still work the same.

2 Likes

This might be helpful.
SPI Bus Design
grafik
The MicroSD card adapter you are using has a tri-state buffer with U1.:smiling_face_with_three_hearts:

grafik

see as well: WiFI Kit 32 V3 pinout question

Thank you everyone for continuing to assist!!

I purchased a cheap logic analyzer and used Logic2 to now confirm without a doubt that the SPI bus is running; so code like @platypii shared is at least having an effect. Actually, translating the Hex in Logic2 / confirming the transaction is working as intended is a bit beyond my skill level. Regardless, I’m seeing data on the CS,MOSI,MISO,SCLK pins which is good.

Given that the pins are communicating and that the adapter works on an Arduino UNO & Arduino Nano 33 BLE this left one thing left to check – the microSD

I swapped my brand new San Disk Ultra 32Gb (which works with Uno & Nano) and instead tried a really old San Disk 2Gb. Funny enough, SD.begin(...) now “mounts”. I guess this board has incompatibility between the SD library and a 32Gb SD card from San Disk.

Anyone know why 32Gb wouldn’t work but 2Gb would?

Not sure, but maybe check what the card filesystem is formatted as? FAT32?

The card that works is Fat16 (SD) and the one that doesn’t is Fat32 (SDHC).

It looks like the board manager installs a version of the SD library into:
…/Library/Arduino15/packages/Heltec-esp32/hardware/esp32/0.0.7/libraries/SD/src/SD.h

This library I think is outdated or simply bad. I am trying to point it directly to:
…/Arduino/libraries/SD/src/SD.h
Which comes from: https://github.com/arduino-libraries/SD
Which supposedly works: https://github.com/arduino-libraries/SD/issues/129

That’s throwing weird errors now too:

undefined reference to `SDLib::SD'

Hi there, any update on the progress? I’ve tried the pin settings as suggested and managed to get the SD card mounted. However, it fails at writing./opening files. Are pullup resistors required for the wiring? I am using the same module described at the beginning of the thread.