SD.begin() after arduino reset

I am using watchdog to reset the arduino, in case that some error occurs. It looks something like this:

void setup()
{
wdt_disable();
Serial.begin(4800);
pinMode(4, OUTPUT);
if(SD.begin(4)) Serial.print("OK"); else Serial.println("FAILURE");
wdt_enable(WDTO_8S);
while(1);
}

The initialisation of the SD card works fine for the first time. After the reset triggered by the watchdog, the initialisation does not work anymore. The same problem occurs when the arduino is resetted by opening the Serial-Monitor interface. Funnily enough, after cutting of power supply for a short time, SD.begin() is working fine.
Anyone got a solution, sothat SD.begin() does work after resetting the arduino?

I solved the problem by leaving out

pinMode(4, OUTPUT);

Does anyone know why the pinMode() statement causes so much trouble?

Does anyone know why the pinMode() statement causes so much trouble?

Perhaps because you said "Here, SD class, pin 4 is yours". Why would you then diddle with it?

Why aren't you setting pin 10 as an OUTPUT? That is necessary for SPI to work properly.

Why aren't you setting pin 10 as an OUTPUT? That is necessary for SPI to work properly.

Good question :roll_eyes: thanks a lot