PDA

View Full Version : SD card does not initialize



bushratariq
- 21st August 2014, 11:22
i am running a simple code that is supposed to create a txt file on sd card and write a line in it. My code starts from initializing command. i checked the return value. and the card does not initialize. what do i do now??? what can be the possible reasons for this???
please help.
Just for information i am using 8gb sd card. if it has anything to do with it. My code now is as follows
My code is as follows

​i checked the return value. and yes the card does not initialize. what do i do now??? what can be the possible reasons for this???
please help.
Just for information i am using 8gb sd card. if it has anything to do with it. My code now is as follows
My code is as follows

void delay (unsigned int k)
for (i=0;i<=k;i++)
{
;
}
void main(void)
{
FSFILE *MyFile;
unsigned char txt[ ]="This is a TEXT message";
TRISB=0;
//
// Initialize the SD card routines
//
FSInit( );
if (FSInit()!=TRUE)
{PORTB=0xFF;
delay(10000);
PORTB=0x0;
delay(10000);
}
//
// Create a new file called MESSAGE.TXT
//
MyFile = FSfopenpgm("MESSAGE.TXT", "w+");
//
// Write message to the file
//
FSfwrite(txt, 1, 22, MyFile);
// Close the file
//
FSfclose(MyFile);
while(1);
}

When i run the code, the portb leds blink. which means the sd card does not initialize.

Dave
- 21st August 2014, 12:00
This is "C". Maybe you should check one of those Arduino forums or Microchip forums depending on which processor you are using.