Micro SD card Expansion Module and XIAO BLE Sense issues

I am using a generic Micro SD card expansion board with the XIAO BLE sense and I am finding that none of my new SD cards will work with the example skectches in the Arduino IDE. I have tried many cards and all but 1 have the same result.

SD card expansion board - Amazon.com

Wiring:
GND - GND
VCC - 3V3
MISO - MISO (9)
MOSI - MOSI (10)
SCK - SCK (8)
CS - 3 (I have tried 7, 1, 2)

Examples I have tried are:

SD library - CardInfo
SdFat library - SdInfo and Quickstart

All cards have been formatted to Fat32 using both Windows and SD Card Formatter, and are between 8 and 32 GB.

I have 1 card that works with all example sketches and a few of my own sketches - It’s a Sandisk Ultra 8GB which is quite a few years old. On top of that I have about 10 other brand new cards of various brands and sizes which do not work with any sketches. (Initialization failed, Is there a Wiring/soldering problem… etc).

Whilst trying to format these cards I noticed that the 1 card that works has an allocation unit size of 512 bytes. None of my other cards have this as an option. Could this be my issue? If so what would my options be to get everything running?

Thanks

Have you tried the non-mbed BSP “Seeed nRF52 Boards 1.1.4”?
The mbed BSP “Seeed nRF52 mbed-enabled Boards 2.9.2” does not work with fast SPI clock.

Yes I’ve tried both and the results are identical. The 1 card works with both options and the rest with neither.

In my case, I slowed down the clock and it works.
How about dropping the SPI clock to about 4MHz?

I tried this using the following block of code in the SdInfo example sketch. Is there a better way? Same results across the board. I tried various clock speeds, mbed, non mbed. Same results. What type of card are you using?

Thanks for your help on this!

// Try to select the best SD card configuration.
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(4))
#else  // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(4))
#endif  // HAS_SDIO_CLASS```

Hi Madz75,
I have tried two different SD boards. The cards were formatted to FAT32 in Windows 11.
The following settings and sketch worked fine.

//----------------------------------------------------------------------------------------------
//BSP : Seeed nRF52 Borads 1.1.1
//Board : Seeed nRF52 Borads / Seeed XIAO nRF52840 Sense
//2023/09/13
//----------------------------------------------------------------------------------------------

/*
  SD card test

  This example shows how use the utility libraries on which the'
  SD library is based in order to get info about your SD card.
  Very useful for testing a card when you're not sure whether its working or not.

  The circuit:
    SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
 		Pin 4 used here for consistency with other Arduino examples


  created  28 Mar 2011
  by Limor Fried
  modified 9 Apr 2012
  by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
//#include <pins_arduino.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
//const int chipSelect = PA4;
//***********************************************************************************
// SCK : D8, MISO : D9, MOSI : D10, GND : GND, VCC : 3V3
const int chipSelect = A2;
//***********************************************************************************

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
//  if (!card.init(SPI_HALF_SPEED, chipSelect)) {    
  if (!card.init(SPI_FULL_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    while (1);
  }

  Serial.print("Clusters:          ");
  Serial.println(volume.clusterCount());
  Serial.print("Blocks x Cluster:  ");
  Serial.println(volume.blocksPerCluster());

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  Serial.println();

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("Volume type is:    FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

Serial Monitor


Initializing SD card...Wiring is correct and a card is present.

Card type:         SD1
Clusters:          115367
Blocks x Cluster:  2
Total Blocks:      230734

Volume type is:    FAT32
Volume size (Kb):  115367
Volume size (Mb):  112
Volume size (Gb):  0.11

Files found on the card (name, date and size in bytes): 
SYSTEM~1/     2023-09-17 08:48:16
  WPSETT~1.DAT  2023-09-17 08:48:16 12
  INDEXE~1      2023-09-17 08:48:22 76



Initializing SD card...Wiring is correct and a card is present.

Card type:         SDHC
Clusters:          945024
Blocks x Cluster:  64
Total Blocks:      60481536

Volume type is:    FAT32
Volume size (Kb):  30240768
Volume size (Mb):  29532
Volume size (Gb):  28.84

Files found on the card (name, date and size in bytes): 
SYSTEM~1/     2023-09-17 08:46:26
  WPSETT~1.DAT  2023-09-17 08:46:26 12
  INDEXE~1      2023-09-17 08:46:28 76

msfujino, thanks for posting that code. I ran it with the same results over and over again. I really think it comes down to the card. To be fair, I have limited knowledge on this and I’ve been googling the hell out of it for a few weeks now without much luck. On the Arduino forums, people have suggested that SD cards be formatted with an allocation unit size of 512 bytes but I can’t see that anyone has said it’s mandatory. From my experience so far it seems to be the case. Do yours have the 512 allocation size or other? I’m desperately trying to get my hands on more Sansdisk Ultra 8GB cards to confirm but they are near impossible to find these days. A friend thinks has has a bunch of them stashed in his desk at work so I will try those if I can get my hands on them. I’m getting sick of ordering random card off Amazon and Ebay only to have them not work. I will post an update If I have any success. I have also ordered some more Micro SD card modules to see if using a diffrent one might help.

The allocation size for a 32 GB SD is 32 kB, and 1024 B for a 128 MB SD.
Since your SD board has a regulator, you should connect 5V to VCC.

Well I’ll be ####ed… I changed to the 5V pin and it works. Which still leaves me with questions. Why do some cards work with the 3V3 Pin and not others? I plan to run this with a 3.7v battery so I will also have to test with that connected. All documentaion I could find says this module will work with 5V or 3.3V as it regulates on board regardless. Thanks for your suggestions - at least I can continue testing now. Time to heat up the soldering iron.

According to the description of the SD board on the Amazon website

  • On-board level conversion circuit, that means the interface level is 5V or 3.3V.
  • Power supply is 4.5V-5.5V, Onboard 3.3V voltage stabilizing circuit

The power supply requires 5V and can be connected to either a 3.3V system or a 5V system.

Consider the case of running XIAO on a 3.7V battery.
If the SD board is powered from XIAO’s 3V3 pin, the voltage is too low and operation becomes unstable.
if the SD board is powered from XIAO’s BAT pad, it may work when the battery voltage is above 3.5V(3.3+0.2V), but stops working when the battery voltage drops.

Great exlpanation. Thanks again for your asnwers. I have wired up the battery as you suggested and everything is running as expected. If I can get 2 hours life out of it that will be more than I need. Cheers!

Hi there, I find this to be the case with my 3.85vdc LIPO batt. works until the battery drops below 3.4vdc.
HTH
GL :slight_smile: PJ