Open GoogleCodeExporter opened 9 years ago
I had the same issue. Here is the code change that I made to SD.cpp to
recognize card changes and allow SD.begin to be called many times...
boolean SDClass::begin(uint8_t csPin) {
/*
Performs the initialisation required by the sdfatlib library.
Return true if initialization succeeds, false otherwise.
*/
//return card.init(SPI_FULL_SPEED, csPin) &&
// volume.init(card) &&
// root.openRoot(volume);
cid_t cidbuf;
if(card.init(SPI_FULL_SPEED, csPin)){
//check to see if we still have the same card in the slot by comparing SD ID
card.readCID(&cidbuf);
if(memcmp(&(card.inslot_),&cidbuf,sizeof(cid_t)) == 0){
//they match so don't need to init vol or open root
return(true);
}else{
//they don't match, close root, init volume, open new root
if(root.isOpen()){
if(root.close() == false){
return(false); //could be problem if there was cache lying around because
//file was left open when SD card was removed
}
}
if(volume.init(card) && root.openRoot(volume)){
memcpy(&(card.inslot_),&cidbuf,sizeof(cid_t));
return(true);
}
}
}
return(false);
}
You will also have to add cid_t inslot_ to SD.h
-Bennett
Original comment by bennettm...@gmail.com
on 22 Sep 2011 at 8:37
Thanks Bennett,
this solution works for me. I have patch the Sd Library with your code and now
i can remove and insert the SD Card without error.
Please add this to the Library it es very usefull for a datalogger
application!!!!!!
Thx Bennett
Matze
Original comment by matthias...@gmail.com
on 17 Mar 2013 at 3:10
Thanks Bennett! This is really helpful. What is the role of "cid_t inslot_"?
Original comment by bdal...@gmail.com
on 22 Mar 2013 at 6:30
Im Test the solution now for some days and it works not stable!
After a random SD-Card changes the file.open gets errors.
I think this solution is not save.
Matze
Original comment by matthias...@gmail.com
on 24 Mar 2013 at 10:37
Bennett, can you please tell me what exactly needs to be modified in SD.h. I
added cid_t inslot_ to SD.h, but the compiler says error: 'class Sd2Card' has
no member named 'inslot_'. Maybe I need to make changes to Sd2Card.h.
Original comment by dxdx...@gmail.com
on 30 Oct 2013 at 7:10
..hallo dxdx347
Have you solve it?
where you have modified the SD.h file to successfully compile with new inslot_
and cid_t variable?
I have the same problem...
Original comment by alessio3...@alice.it
on 8 Nov 2013 at 11:26
Please where to add cid_t and inslot_ in SD.h?
Original comment by maria.ce...@gmail.com
on 27 Mar 2015 at 6:55
Original issue reported on code.google.com by
linux-...@o2online.de
on 21 Jan 2011 at 2:26