mofan2 发表于 2012-3-7 18:42:32

求教傻孩子 Petit FatFs 的写函数 pf_write() 数据写不进去,求高手解脱,求例程

Petit FatFs的写函数 pf_write() 数据写不进去,求高手解脱,求例程其他函数功能都好使就是写不进去求高手 给解释几句呗非常感谢分享个例程就万分感谢了
 

823032003 发表于 2012-3-7 18:59:53

kao 2位论坛的大侠 都要出来给你解答问题//////

mofan2 发表于 2012-3-7 19:24:52

抱歉啊我就随便问问啊希望能大家百忙之中 能抽空 看下我的小问题。 ./emotion/em007.gif

coolhe 发表于 2012-4-5 17:30:25

需要详细阅读官网中关于pf_write的说明:
File write operation must be done in following sequence.

1.pf_lseek(ofs); read/write pointer must be moved to sector bundary prior to initiate write operation or it will be rounded-down to the sector boundary.
2.pf_write(buff, btw, &bw); Initiate write operation. Write first data to the file.
3.pf_write(buff, btw, &bw); Write next data. Any other file function cannot be used while a write operation is in progress.
4.pf_write(0, 0, &bw); Finalize the write operation. If read/write pointer is not on the sector boundary, left bytes in the sector will be filled with zero.

coolhe 发表于 2012-4-5 17:31:15

以下是我测试的一个小例程,供参考,可能不一定全面:

//The following module is to write bytes to txt file.
//Note:it use the new string to replace all of the old bytes.
//For example:the old bytes:123456789abcefg
//                                     123456789
//                  the new string:Hello world!
//                  The result:Hello world!
//                                 Hello world!
    rc = pf_open("write.txt");
    pf_lseek(rc);
    for (;;)
    {
      rc = pf_write("Hello world!\r\n", 14, &bw);
      if (rc || !bw) break;
    }
    rc = pf_write(0, 0, &bw);         //Finalize the write operation.
    ClearLED3;
    while(1);
页: [1]
查看完整版本: 求教傻孩子 Petit FatFs 的写函数 pf_write() 数据写不进去,求高手解脱,求例程