STC89C516RD+ 移植FATFS 求大虾帮助
STC89C516RD+ 这个单片机 有1K的RAM我感觉应该可以用FATFS吧于是就尝试了下,尝试的结果是系统挂载成功列举文件成功 打开文件成功 读文件成功 就是写文件不成功 郁闷啊奋战了 好几天了一直写不进去东西代码共享一下,除了写其他都正常 有同意问题的可以参考 求高手 解脱我fatfs移植STC51的片子ourdev_724689VWTMHE.rar(文件大小:158K) (原文件名:Keil temp.rar) 后来发现了点问题做实验的时候复制了点东西,没有做广告的意思哈真是弄不明白了求解脱来了 你得先确认一下你磁盘底层的读写函数有没有问题 DRESULT disk_writep (
BYTE* buff, /* Pointer to the data to be written, NULL:Initiate/Finalize write operation */
DWORD sc /* Sector number (LBA) or Number of bytes to send */
)
{
DRESULT res;
unsigned int retry;//
WORD bc;
static WORD wc;
res=RES_ERROR;
if (!buff)
{
if (sc) // (0,1) Initiate write process
{
if (SD_Write_Cmd(CMD24,card_type==2?sc:sc<<9,0xff)== 0)/* WRITE_SINGLE_BLOCK */
{
SD_spi_write(0xFF); /* Data block header */
SD_spi_write(0xFE);
wc = 512; /* Set byte counter */
res = RES_OK;
}
}
else //// (0.0)Finalize write process
{
while (wc--) SD_spi_write(0); /* Fill left bytes with zeros */
SD_spi_read();
SD_spi_read();//忽略CRC校验(两个字节)
if ((SD_spi_read() & 0x1F) != 0x05) /* Receive data resp and wait for end of write process in timeout of 300ms */
{
SD_CS_DEASSERT; /*AAA='110'-data rejected due to write error*/
return 1;
}
do
{
if(retry++ > 0xfffe)
{
SD_CS_DEASSERT;
return RES_ERROR;
}
}while(SD_spi_read()!=0xff); //wait until the SD is not busy
SD_CS_DEASSERT;
SD_spi_write(0xff); //等待8个 clk
res = RES_OK;
}
return res;
}
else //(1.1)Send data to the disk
{
bc=(WORD)sc;
while(bc&&wc)
{
SD_spi_write(*buff++);
bc--; wc--;
}
res=RES_OK;
}
return res;
} 确认了不知道几遍了 不懂,不过希望你找到解决方法共享,顶一下!! 学习下 本帖最后由 lsnow888 于 2012-7-15 14:14 编辑
最近也在搞fatfs,也遇到这么个问题。不过突然发现:写不进去是因为要写的txt文件是空的。也就是f.size=0,如果你预先在txt文件里写入一堆数据,写函数就是可以了。因为在pf_write()函数内有这么一句话:
remain = fs->fsize - fs->fptr;
if (btw > remain) btw = (WORD)remain; /* Truncate btw by remaining bytes */
while (btw)
{
……
if (disk_writep(p, wcnt)) goto fw_abort; /* Send data to the sector */
}
如果文件是空的,那么remain就是0了。这样下面的while()就不执行了。写不进去 。
还有就是执行写之前应该加一句: pf_lseek(bytes); 指定一下偏移量。 没搞过···mark JIHAO
页:
[1]