SdFat, SparkFun microSD Transflash Breakout & Boron

Hi All,

I realise there are multiple posts around this topic, but did not find any specifically that relates to this issue with a boron and the SparkFun microSD Transflash Breakout.

My Boron is wired as follows:
A2 - CS
A3 - SCK
A4 - DO
A5 - DI
GND - GND
3V3 - VCC

The correct wiring as @ScruffR suggested for this app is (SD - BORON):
DI - D12 (MO)
DO - D11 (MI)
SCK - D13 (SCK)
CS - A2 (A2 as it’s set in app, Scruff mentioned A5 is default)
GND - GND
3v3 - VCC

The Serial is printing out the following:

Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X20,0XFF

Apologies if I should have posted this in an existing thread. Have I made any obvious mistakes?

The Micro SD seems to be formatted as FAT32 and I am testing with the following particle code:

// This #include statement was automatically added by the Particle IDE.
#include <SdFat.h>

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

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

// #elif SPI_CONFIGURATION == 2
// // 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;

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

#endif  // SPI_CONFIGURATION

//------------------------------------------------------------------------------

File myFile;

void setup() {

    
    
  Serial.begin(9600);
  // Wait for USB Serial 
  while (!Serial) {
    SysCall::yield();
  }
  
 // 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_FULL_SPEED)) {
    sd.initErrorHalt();
  }

  // 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:
  myFile.close();
  Serial.println("done.");

  // 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) {
    Serial.write(data);
  }
  // close the file:
  myFile.close();
}

void loop() {
  // nothing happens after setup
}

On the Boron the SPI pins are as shown here
https://docs.particle.io/reference/device-os/firmware/boron/#spi

On the board they are labled SCK, MO, MI and A5 for the default SS but you can use any (including A2).

The DO (Data Out) pin on the microSD wants to be connected to MI (Master In) and DI (Data In) to MO (Master Out).

1 Like

Thanks for your help, all sorted now.

1 Like

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