FATFS 的几个函数用法


FATFS 的几个函数用法:

 

 FATFS *fs, fatfs;

 fs = &fatfs;
 f_mount(0, fs);

 b = f_open(&infile,"SD.txt",FA_CREATE_NEW);    //创建新文件
 f_close(&infile);    //关闭文件

 b = f_open(&infile,"SD.txt", FA_WRITE);   //以写方式打开文件
 f_puts((char *)buff2,&infile);  //文件内写入字符串
 f_puts((char *)buff2,&infile);  //文件内写入字符串
 f_puts((char *)buff2,&infile); //文件内写入字符串
 f_close(&infile);  //关闭文件

 b = f_open(&infile,"SD.txt",FA_WRITE);   //以写方式打开文件
 b = infile.fsize;       //获得文件大小
 f_lseek(&infile,b);  //移动文件指针
 f_puts(buff3,&infile); //从文件内数据的最后写入字符串
 f_close(&infile);    //关闭文件

 b = f_open(&infile,"SD.txt",FA_READ);  //以读方式打开文件
 f_read(&infile,buff1,50,&rc);  //从文件内读50字节赋给 buff1数组
 f_close(&infile);  //关闭文件

// f_unlink("SD.txt");  //删除文件

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 FATFS fs;            // Work area (file system object) for logical drive
 FIL fileuse;      // file objects
 unsigned char buffer[512]; // file copy buffer
 unsigned int nfr, nfw;         // File R/W count
void TestFATFS_Read(void)

  //FILINFO finfo;
  //DIR dirs;
  //char name[]={"TEST.TXT"};
  uint8_t result;
  char path[50]={"0:/SD/BIN.TXT"};  

  printf("********* Test FATFS Read begin*************\n");  
  f_mount(0, &fs); 
  result = result;

  if( (f_open(&fileuse,path, FA_OPEN_EXISTING |FA_READ))!=FR_OK) {printf("f_open() Failed !\n");return;}//以读方式打开文件        
  if( (f_read(&fileuse, buffer, sizeof(buffer), &nfr))!=FR_OK)   {printf("f_read() Failed !\n");return;}
  printf("%s\n",buffer);
  f_close(&fileuse);

  printf("********* Test FATFS Read over*************\n");
}

void TestFATFS_Write(void)

  char path[50]={"0:/SD/BIN.TXT"};   
  unsigned char cont[]={"read write OK !"};
  printf("********* Test FATFS Write begin*************\n");  
  f_mount(0, &fs); 
  
  if( (f_open(&fileuse,path, FA_OPEN_ALWAYS |FA_WRITE))!=FR_OK) {printf("f_open() Failed !\n");return;}//以读方式打开文件        
  if( (f_write(&fileuse, cont, sizeof(cont), &nfr))!=FR_OK)   {printf("f_read() Failed !\n");return;}
  f_close(&fileuse);

  printf("********* Test FATFS Write over*************\n");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值