|
Hi everyone I used the Fat Library.It works Corectly but I have just one problem.f_write function doesn't work correctly and it doesn't return FR_OK.Can somebody help me?It creates new file and it read an existing file but it can't write to a file.this is my code:
#include "project.h" #include "Demo.h" #include "Font.h" #include "t6963c.h"
#include "mmc.c" #if TINY_FAT #include "tff.c" #else #include "ff.c" #endif
WORD mmc_ok=0,n; char filename[20]="test.txt"; char str[512]="File Writing Is OK!!!!!!!!"; FATFS fat; FIL file; //*************************************************************** void InitDevice() { AT91C_BASE_RSTC->RSTC_RMR=0xA5000000 | AT91C_RSTC_URSTEN; //Enable External RESET } //***************************************************************
void main() { InitDevice(); LCD_Setup(); LCD_Init(); LCD_ClearText(); LCD_ClearGraph(); if(disk_initialize(0)!=STA_NOINIT) { //xmit_datablock(str, 0xFE) LCD_Print(0,0,"MMC Init OK"); mmc_ok=1; f_mount(0,&fat); } else LCD_Print(10,7,"MMC Not Init"); if(mmc_ok) { if(f_open(&file,filename,FA_CREATE_ALWAYS | FA_WRITE)==FR_OK) //Create A New File { f_sync(&file); if(f_write(&file,str,10,&n)==FR_OK) //Writin To Opened File LCD_Print(0,3,"File Writing OK"); else LCD_Print(0,3,"File Writing Error"); f_close(&file); //Close Opened File if(f_open(&file,filename,FA_OPEN_EXISTING | FA_READ)==FR_OK) LCD_Print(0,4,"File Open For Read OK"); else LCD_Print(0,4,"File Open Error"); f_sync(&file); str[0]='\0'; if(f_read(&file,str,50,&n)==FR_OK) //Reading From Opened File { LCD_Print(0,6,"File Readig OK"); str[50]='\0'; LCD_Print(0,8,str); } else LCD_Print(0,6,"File Reading Error"); } } while(1) { } }
|