Continue to Site

# f_open(&fdst, "0:dstfile.txt", FA_CREATE_ALWAYS | FA_WRITE)

Status
Not open for further replies.

#### anhnha

##### Full Member level 6
May be this is a stupid question but i cannot figure out, hope anyone can help.
After i use f_open() to create dstfile.txt, where i can find this file? I think that it must be located in C disk but I dont see any file is created.
res = f_open(&fdst, "C:\\dstfile.txt", FA_CREATE_ALWAYS | FA_WRITE);
PS: This function is in FATFS library here: http://elm-chan.org/fsw/ff/00index_e.html

#### internetuser2k12

##### Banned
Is it not a function to create file on SD cards? If you are simulating in Proteus the file will be created in the .mmc file.

Is it res = f_open(&fdst, "C:\\dstfile.txt", FA_CREATE_ALWAYS | FA_WRITE); or res = f_open(&fdst, "C:\dstfile.txt", FA_CREATE_ALWAYS | FA_WRITE);

It might be res = f_open(&fdst, "C:dstfile.txt", FA_CREATE_ALWAYS | FA_WRITE);

It is clearly mentioned that

/* Create destination file on the drive 0 */
res = f_open(&fdst, "0:dstfile.dat", FA_CREATE_ALWAYS | FA_WRITE);

Last edited:

#### anhnha

##### Full Member level 6
Thank you again, internetuser2k12 :lol:
I am trying to learn how to use fatfs function and the bellow is code that I used:
Code:
int main (void)
{

FATFS fs1;         /* Work area (file system object) for logical drive */
FIL fsrc1;         /* file objects */
FRESULT res1;
UINT br1;

char date[30]="Date : ", _time[30]="Time : ";

char pathname[50]="0:/Sell/";
uint8_t textFileBuffer[8]= "write to file" ;
res1 = f_open( &fsrc1 , "C:\\Demo.TXT" , FA_CREATE_NEW | FA_WRITE);
if ( res1 == FR_OK )
{
// Write buffer to file
res1 = f_write(&fsrc1, textFileBuffer, sizeof(textFileBuffer), &br1);
printf("Demo.TXT successfully created        \r\n");
//close file
f_close(&fsrc1);
} else
if ( res1 == FR_EXIST )
{
printf("Demo.TXT created in the disk      \r\n");
}

}
I think it must create a file Demo.TXT in C disk and write "write to file" string into it but when i look C disk, i didn't see any file created.
PS: I will use these function for my sd card but now i want to test these functions.

#### internetuser2k12

##### Banned
Are you running your code on PIC? If yes where is C drive in it? If you are simulatinf in Proteus then there is no Drive in .mmc file. If you are creating file on SD card then SD card is not your c drive.

Are you writing a c program for your PC to create file on C drive using FAtfs library?

#### anhnha

##### Full Member level 6
Here is what I am doing:
2. I used avr from that file and modifies main.c into sample2.c
3. Then I complied this project in avr studio without error.
But now I cannot find any file that is created as the code above!

#### Attachments

• sample2.rar
388.8 KB · Views: 63

#### internetuser2k12

##### Banned
How can your PIC read the drive system of your PC when you are simulating in proteus?

Can you show how you have used f_mount();? It says drive should be 0 to 9 it is a number not something like C:\\

Last edited:

Status
Not open for further replies.