Content originally posted in LPCWare by james on Thu Jan 05 03:12:29 MST 2012
Hi there, I am trying to save data logged data into sdcard and/or read sdcard value to control leds.
i tried to extend the efsl_demo from red_code_examples but i cant seems to write anything. here is my code:
{
int8_t res;
MESSAGE("\nRDB1768 EFSL / microSD card Demonstration\n");
MESSAGE("=========================================\n");
MESSAGE("CARD init...");
if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
MESSAGE("failed with %i\n",res);
}
else {
MESSAGE("ok\n");
MESSAGE("Directory of 'root':\n");
ls_openDir( &list, &(efs.myFs) , "/");
while ( ls_getNext( &list ) == 0 ) {
list.currentEntry.FileName
[LIST_MAXLENFILENAME-1] = '\0';
MESSAGE( "%s ( %li bytes )\n" ,
list.currentEntry.FileName,
list.currentEntry.FileSize ) ;
}
}
// This part is provided by red_code_examples and is working perfectly
Here is my code for writing a file
euint8 *buffer = "1234567" ;
euint16 e = 0;
euint8 buffer1[512] ;
euint16 f ;
File filew, filer;
/*Open file for writing */
if (file_fopen (&filew , &efs.myFs , "read3.txt" , 'a' ) !=0){
MESSAGE("Could not open file for writing. \n", res ) ;
return -1;
}
else
MESSAGE("File opened for writing. \n", res) ;
/* Write buffer to file */
// strcpy((char*)buf, "Martin hat's angehaengt\n");
int ll;
if ( (file_write (&filew , 512 , *buffer )) == strlen( buffer ) )
// if ( (file_write( &filew, strlen((char*)buf), buf )) == strlen((char*)buf))
MESSAGE("File written . %d %d \n", file_write, strlen(buffer));
else
MESSAGE("Could not write file. \n", res);
fclose (&filew);
it returns "file written"
It creates a file call "read3.txt" but it doesnt write any thing into it. the file is has 0bytes.
I copied it from a user manual found at efsl.be
I am using a rdb1768v2r4 board and a 2gb micro sd-card formatted to fat16 with 32kb allocation unit size.
Anyone who has used this before please kindly point out what i might have missed. Thank you :)