Difficulties with SD Card Reader Integration

New to Particle and need some assistance on an SD card reader.

I am using the SDFat library in conjunction with a sparkfun SD card reader which I soldered some pins on. I am using an example code provided by GitHub to test out the reader and keep receiving an error- “SD errorCode: 0XF,0X1”. Was not sure what was causing the error since I am unfamiliar with the registers of the Particle Electron board in which I am using. Just looking for any assistance. Any help would be greatly appreciated.

I have tried to tweak the code to work with the wiring/pin setup. (Basically I tried to use pins A2,A3,A4,A5)

The full error says: “error: opening test.txt for write failed
SD errorCode: 0XF,0X1”

Below is the example code:

 #include "SdFat/SdFat.h"

// Pick an SPI configuration.
// See SPI configuration section below (comments are for photon).
// Setup SPI configuration.
// Primary SPI with DMA
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFat sd;
const uint8_t chipSelect = A2;

// Secondary SPI with DMA
// SCK => D4, MISO => D3, MOSI => D2, SS => D1
//SdFat sd(1);
//const uint8_t chipSelect = D1;

// Primary SPI with Arduino SPI library style byte I/O.
// SCK => A3, MISO => A4, MOSI => A5, SS => A2 (default)
SdFatLibSpi sd;
const uint8_t chipSelect = SS;

// Software SPI.  Use any digital pins.
// MISO => A4, MOSI => A5, SCK => A3, SS => A2
SdFatSoftSpi<A4, A5, A3> sd;
const uint8_t chipSelect = A2;



File myFile;

void setup() {

  // Wait for USB Serial 
  while (!Serial) {
 // Serial.println("Type any character to start");
  //while (Serial.read() <= 0) {
   // SysCall::yield();

  // Initialize SdFat or print a detailed error message and halt
  // Use half speed like the native library.
  // Change to SPI_FULL_SPEED for more performance.
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {

  // open the file for write at end like the "Native SD library"
  if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("opening test.txt for write failed");
  // if the file opened okay, write to it:
  Serial.print("Writing to test.txt...");
  myFile.println("testing 1, 2, 3.");
  myFile.printf("fileSize: %d\n", myFile.fileSize());
  // close the file:

  // re-open the file for reading:
  if (!myFile.open("test.txt", O_READ)) {
    sd.errorHalt("opening test.txt for read failed");
  Serial.println("test.txt content:");

  // read from the file until there's nothing else in it:
  int data;
  while ((data = myFile.read()) >= 0) {
  // close the file:

void loop() {
  // nothing happens after setup

Which one exactly? (there are several)
And what did you need to solder?
Why would you want to use SPI_CONFIGURATION 3?
If you are using the HW SPI pins A2~A5 anyway, you might consider using SPI_CONFIGURATION 0.

1 Like

I am using this as my SD card board:

I soldered pins on to allow it to plug into a breadboard. http://rathyelectronics.com/eshop/images/6pin.jpg

Originally I used SPI_CONFIGURATION 0, but received the same error message. The SPI_CONFIGURATION 2 and 3 also gave me the error message. I know it can’t be a very difficult fix, but I am not sure what is wrong. Currently I am using a 4GB SanDisk microSD card which I didn’t think needed any reformatting.

I see. That board should be fine.
To cover the basics:

  • How have you hooked the board up?
  • Is your SD formatted FAT32?

I believe that SDFAT does not support FAT32. This means that it cannot access 4GB partitions.

You’ll need a 2GB (or less) partition, explicitly marked as a FAT filesystem, and not FAT32 (which is what nearly all modern tools will mark it as.)

The SDFAT library documentation may recommend a tool to use.

Maybe this has all changed; this is my recollection, tho.

Yup. I’m wrong. I did also learn that the error you’re having is a result of the library being unable to read card properties see by the manufacturer.

Are you sure it is wired up correctly?

I’d say it does support FAT32

yeah I corrected my post after I wrote that, and before you replied. Couldn’t figure out how to do a strikethrough text effect.

I see, sorry - I hadn’t read to the end :blush:

You can use this to strike out

 This is a <del>wrong</del> word and this is <strike>obsolete</strike>.

which would render like this

This is a wrong word and this is obsolete.

1 Like

So I was finally able to reformat the SD card to FAT32 and now it seems to be working. I really appreciate the help… and sorry for the late response.