Arduino using two cards..error in file1

i am using sdfat library from the below link

 * Example use of two SD cards.
#include <SdFat.h>
#include <SdFatUtil.h>
#error You must set USE_MULTIPLE_CARDS nonzero in SdFatConfig.h

SdFat sd1;
const uint8_t SD1_CS = 10;  // chip select for sd1

SdFat sd2;
const uint8_t SD2_CS = 9;   // chip select for sd2

const uint8_t BUF_DIM = 100;
uint8_t buf[BUF_DIM];

const uint32_t FILE_SIZE = 1000000;
const uint16_t NWRITE = FILE_SIZE/BUF_DIM;
// print error msg, any SD error codes, and halt.
// store messages in flash
#define errorExit(msg) errorHalt_P(PSTR(msg))
#define initError(msg) initErrorHalt_P(PSTR(msg))
void setup() {
  while (!Serial) {}  // wait for Leonardo
  PgmPrint("FreeRam: ");

  // fill buffer with known data
  for (int i = 0; i < sizeof(buf); i++) buf[i] = i;
  PgmPrintln("type any character to start");
  while ( <= 0) {}
  delay(400);  // catch Due reset problem

  // disable sd2 while initializing sd1
  pinMode(SD2_CS, OUTPUT);
  digitalWrite(SD2_CS, HIGH);
  // initialize the first card
  if (!sd1.begin(SD1_CS)) {
  // create DIR1 on sd1 if it does not exist
  if (!sd1.exists("/DIR1")) {
    if (!sd1.mkdir("/DIR1")) sd1.errorExit("sd1.mkdir");
  // initialize the second card
  if (!sd2.begin(SD2_CS)) {
 // create DIR2 on sd2 if it does not exist
  if (!sd2.exists("/DIR2")) {
    if (!sd2.mkdir("/DIR2")) sd2.errorExit("sd2.mkdir");
  // list root directory on both cards
  PgmPrintln("------sd1 root-------");;
  PgmPrintln("------sd2 root-------");;

  // make /DIR1 the default directory for sd1
  if (!sd1.chdir("/DIR1")) sd1.errorExit("sd1.chdir");
  // make /DIR2 the default directory for sd2
  if (!sd2.chdir("/DIR2")) sd2.errorExit("sd2.chdir");
  // list current directory on both cards
  PgmPrintln("------sd1 DIR1-------");;
  PgmPrintln("------sd2 DIR2-------");;
  // remove RENAME.BIN from /DIR2 directory of sd2
  if (sd2.exists("RENAME.BIN")) {
    if (!sd2.remove("RENAME.BIN")) {
      sd2.errorExit("remove RENAME.BIN");
  // set the current working directory for open() to sd1
  // create or open /DIR1/TEST.BIN and truncate it to zero length
  SdFile file1;
  if (!"TEST.BIN", O_RDWR | O_CREAT | O_TRUNC)) {
  PgmPrintln("Writing TEST.BIN to sd1");
  // write data to /DIR1/TEST.BIN on sd1
  for (int i = 0; i < NWRITE; i++) {
    if (file1.write(buf, sizeof(buf)) != sizeof(buf)) {
  // set the current working directory for open() to sd2
  // create or open /DIR2/COPY.BIN and truncate it to zero length
  SdFile file2;
  if (!"COPY.BIN", O_WRITE | O_CREAT | O_TRUNC)) {
  PgmPrintln("Copying TEST.BIN to COPY.BIN");
  // copy file1 to file2
  uint32_t t = millis();

  while (1) {
    int n =, sizeof(buf));
    if (n < 0) sd1.errorExit("read1");
    if (n == 0) break;
    if (file2.write(buf, n) != n) sd2.errorExit("write2");
  t = millis() - t;
  PgmPrint("File size: ");
  PgmPrint("Copy time: ");
  PgmPrintln(" millis");
  // close TEST.BIN
  // rename the copy
  if (!sd2.rename("COPY.BIN", "RENAME.BIN")) {
void loop() {}

i am getting error as

FreeRam: 439
type any character to start
------sd1 root-------
------sd2 root-------
------sd1 DIR1-------
------sd2 DIR2-------

error: file1
SD errorCode: 0X13,0XFF

can anyone let me know what the problem is...

A hardware write error occurred on sd1.

/** card returned an error token as a response to a write operation */
uint8_t const SD_CARD_ERROR_WRITE = 0X13;

In this statement

  if (!"TEST.BIN", O_RDWR | O_CREAT | O_TRUNC)) {

Sometimes this happens when the wires to the SD are not short and neat. You could try a lower SPI speed like this by adding a SPI_HALF_SPEED parameter to begin().

  // initialize the first card
  if (!sd1.begin(SD1_CS, SPI_HALF_SPEED)) {

i have connected one sd card chip select to pin 10 and other sd card card to pin 9.....and remaining MISO,MOSI,SCK,5V and GND to both sd cards.
is it right connection?

Thank you.


The SDcards are 3.3V, so hopefully you have a voltage regulator and signal level shifter wired there..

ok thankyou...