Hi,
am trying to write a file in sd card using f_write function but its not writing to it....
int
Cmd_write(int argc, char *argv[])
{
FRESULT fresult;
unsigned short usBytesRead=0;
//
// First, check to make sure that the current path (CWD), plus the file
// name, plus a separator and trailing null, will all fit in the temporary
// buffer that will be used to hold the file name. The file name must be
// fully specified, with path, to FatFs.
//
if(strlen(g_cCwdBuf) + strlen(argv[1]) + 1 + 1 > sizeof(g_cTmpBuf))
{
UARTprintf("Resulting path name is too long\n");
return(0);
}
//
// Copy the current path to the temporary buffer so it can be manipulated.
//
strcpy(g_cTmpBuf, g_cCwdBuf);
//
// If not already at the root level, then append a separator.
//
if(strcmp("/", g_cCwdBuf))
{
strcat(g_cTmpBuf, "/");
}
//
// Now finally, append the file name to result in a fully specified file.
//
strcat(g_cTmpBuf, argv[1]);
//
// Open the file for reading.
//
fresult = f_open(&g_sFileObject, g_cTmpBuf, FA_READ|FA_WRITE);
//
// If there was some problem opening the file, then return an error.
//
if(fresult != FR_OK)
{
return(fresult);
}
//
// Enter a loop to repeatedly read data from the file and display it, until
// the end of the file is reached.
//
//do
//{
// strcpy(Buf, g_cTmpBuf);
//
// Read a block of data from the file. Read as much as can fit in the
// temporary buffer, including a space for the trailing null.
//
fresult = f_write(&g_sFileObject, Buf, sizeof(Buf) - 1,
&usBytesRead);
//
// If there was an error reading, then print a newline and return the
// error to the user.
//
if(fresult != FR_OK)
{
UARTprintf("\n");
return(fresult);
}
//
// Null terminate the last block that was read to make it a null
// terminated string that can be used with printf.
//
// g_cTmpBuf[usBytesRead] = 0;
//
// Print the last chunk of the file that was received.
//
// UARTgets( g_cTmpBuf, sizeof(g_cTmpBuf));
//}
//while(usBytesRead == sizeof(g_cTmpBuf) - 1);
//
// Return success.
//
return(0);
this is am trying to write can anyone help me out