Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

SD.Begin(int, int. int. int) can only be called once. #7

Closed
davidstellini opened this issue May 2, 2013 · 3 comments
Closed

SD.Begin(int, int. int. int) can only be called once. #7

davidstellini opened this issue May 2, 2013 · 3 comments

Comments

@davidstellini
Copy link

Demo code:

include <SD.h>

void setup()
{
Serial.begin(115200);
Serial.println("Starting...");
if (!SD.begin(53,2,4,3)) { // chipSel, mosi, miso, sck
Serial.println(F("initialization failed!"));
} else {
Serial.println(F("initialization done."));
}

if (!SD.begin(53,2,4,3)) { // chipSel, mosi, miso, sck
Serial.println(F("initialization failed!"));
} else {
Serial.println(F("initialization done."));
}
}

void loop(void) {

}

Output:

Starting...
initialization done.
initialization failed!

Expected output:
Starting...
initialization done.
initialization done.

@Jeroi
Copy link

Jeroi commented Mar 31, 2014

This is not bug. You only need to initialise Sd library once. You can then make checks with File myfile = SD.open("file") that shall return file or 0 if not working. You can check if (myfile) then do work.

@dariosalvi78
Copy link

Hi,

this is definitely a bug, in fact, if you have more than one SPI device you must call begin() each time you need to switch from another device to the SD card.
I have had the problem myself.

Solution:
in the file named SD.cpp, in function begin() (line 337) add this instruction before the return statement:
if(root.isOpen()) root.close();

this has solved the problem for me.

@ladyada
Copy link
Member

ladyada commented Jul 25, 2019

this library fork is being archived - please use the SdFat Library instead (its much better) for any advanced SD card needs!

@ladyada ladyada closed this as completed Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants