搜索
bottom↓
回复: 2

(SD和MMC)FAT32初始化有问题==》DX们请进

[复制链接]

出0入0汤圆

发表于 2008-4-16 16:25:33 | 显示全部楼层 |阅读模式
我在用PIC  CCSC时的FAT例子发现FAT不能初始化。 到CCS论坛上发现也有好多人问过这个问题,现还没解决。
说明:低层的SPI驱动是OK了,就是FAT不能初始化。程序如下:


/*
signed int fat_init()
Summary: Initializes global variables that are essential for this library working
Returns: EOF if there was a problem with the media, GOODEC if everything went okay.
Note: This must be called before any other function calls in this library.
*/
signed int fat_init()
{
   int ec = 0;

   int
      FATs,
      Sectors_Per_Cluster;

   int16
      Bytes_Per_Sector,
      Reserved_Sectors,
      Small_Sectors;

   int32
      Hidden_Sectors,
      Large_Sectors;

#ifdef FAT32
   int32 Sectors_Per_FAT;
#else // FAT16
   int16
      Root_Entries,
      Sectors_Per_FAT;
#endif // #ifdef FAT32

   // initialize the media
   ec += mmcsd_init();

   // start filling up variables
   ec += mmcsd_read_data(11, 2, &Bytes_Per_Sector);
   ec += mmcsd_read_data(13, 1, &Sectors_Per_Cluster);
   ec += mmcsd_read_data(14, 2, &Reserved_Sectors);
   ec += mmcsd_read_data(16, 1, &FATs);
#ifdef FAT16
   ec += mmcsd_read_data(17, 2, &Root_Entries);
#endif // #ifdef FAT16
   ec += mmcsd_read_data(19, 2, &Small_Sectors);
#ifdef FAT32
   ec += mmcsd_read_data(36, 4, &Sectors_Per_FAT);
#else // FAT16
   ec += mmcsd_read_data(22, 2, &Sectors_Per_FAT);
#endif // #ifdef FAT32
   ec += mmcsd_read_data(28, 4, &Hidden_Sectors);
   ec += mmcsd_read_data(32, 4, &Large_Sectors);
#ifdef FAT16
   Next_Free_Clust = 2;
#else
   ec += mmcsd_read_data(0x3EC, 4, &Next_Free_Clust);
#endif
   if(ec != GOODEC)
      return EOF;

   // figure out the size of a cluster
   Bytes_Per_Cluster = Sectors_Per_Cluster * Bytes_Per_Sector;

   // figure out how long one FAT is
   FAT_Length = Sectors_Per_FAT * (int32)Bytes_Per_Sector;

   // figure out where the FAT starts
   FAT_Start = Reserved_Sectors * Bytes_Per_Sector;

   // figure out where the root directory starts
   Root_Dir = FAT_Start + (FATs * FAT_Length);

   // figure out where data for files in the root directory starts
#ifdef FAT32
   Data_Start = Bytes_Per_Cluster + Root_Dir;
#else // FAT16
   Data_Start = (Root_Entries * 0x20) + (Bytes_Per_Sector - 1);
   Data_Start /= Bytes_Per_Sector;
   Data_Start += Reserved_Sectors + (FATs * Sectors_Per_FAT);
   Data_Start *= Bytes_Per_Sector;
#endif // #ifdef FAT32

   return GOODEC;
}

/*

出0入0汤圆

发表于 2009-8-2 16:01:11 | 显示全部楼层
可以把程序发来给你瞧瞧.
E-MAL;lixinmincn@163.com
QQ:158993042

出0入0汤圆

发表于 2009-8-5 13:10:40 | 显示全部楼层
全部使用无符号数。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-9 04:16

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表