SD card

Hello !

Please for help.

I have wrote code for writing datas to SD card. Everything is perfect. But when I ejected card and then inserted card back arduino stoped write to SD card.
I must to reset program ( button on arduino) and system working normaly again.
I have already tryed function SD.exists , but system in not work.
I would like that program writing data on SD card after I insert card again.

I have added my code.

Thank you in advance !

Tomaž

sketch_apr30a.ino (5.48 KB)

Well, what's wrong with resetting the Arduino?

But when I ejected card and then inserted card back arduino stoped write to SD card.

The SD card has a micro-controller that loses state when you remove power. You may also lose data if any files are open for write.

You must reinitialize the SD when you reinsert the card. Unfortunately SD.h has a bug that prevents a second call to SD.begin().

There is a simple fix so begin() can be called again but the Arduino Company has not installed the fix.

Here is the fix so you can call SD.begin() after you reinsert the card.

boolean SDClass::begin(uint8_t csPin) {
  /*

    Performs the initialisation required by the sdfatlib library.

    Return true if initialization succeeds, false otherwise.

   */

  root.close()  // <----------------- Insert this line.

  return card.init(SPI_HALF_SPEED, csPin) &&
         volume.init(card) &&
         root.openRoot(volume);
}

You will need to find the SD.cpp in the SD.h library file and edit it.