6647|3

4

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

对SD卡的CSD寄存器的一些疑惑求解 [复制链接]

我用串口显示SD卡的CSD寄存器中的值,结果是从串口中读出 SD的容量为“”,这是怎么回事啊,请高手指点
此帖出自stm32/stm8论坛

最新回复

自己看吧   //!< Byte 0 //   tmp = (u8)((CSD_Tab[0] & 0xFF000000) >> 24);   cardinfo->SD_csd.CSDStruct = (tmp & 0xC0) >> 6;   cardinfo->SD_csd.SysSpecVersion = (tmp & 0x3C) >> 2;   cardinfo->SD_csd.Reserved1 = tmp & 0x03;   //!< Byte 1 //   tmp = (u8)((CSD_Tab[0] & 0x00FF0000) >> 16);   cardinfo->SD_csd.TAAC = tmp;   //!< Byte 2 //   tmp = (u8)((CSD_Tab[0] & 0x0000FF00) >> 8);   cardinfo->SD_csd.NSAC = tmp;   //!< Byte 3 //   tmp = (u8)(CSD_Tab[0] & 0x000000FF);   cardinfo->SD_csd.MaxBusClkFrec = tmp;   //!< Byte 4 //   tmp = (u8)((CSD_Tab[1] & 0xFF000000) >> 24);   cardinfo->SD_csd.CardComdClasses = tmp > 16);   cardinfo->SD_csd.CardComdClasses |= (tmp & 0xF0) >> 4;   cardinfo->SD_csd.RdBlockLen = tmp & 0x0F;      //!< Byte 6 //   tmp = (u8)((CSD_Tab[1] & 0x0000FF00) >> 8);   cardinfo->SD_csd.PartBlockRead = (tmp & 0x80) >> 7;   cardinfo->SD_csd.WrBlockMisalign = (tmp & 0x40) >> 6;   cardinfo->SD_csd.RdBlockMisalign = (tmp & 0x20) >> 5;   cardinfo->SD_csd.DSRImpl = (tmp & 0x10) >> 4;   cardinfo->SD_csd.Reserved2 = 0; //!< Reserved //   if ((CardType == SDIO_STD_CAPACITY_SD_CARD_V1_1) || (CardType == SDIO_STD_CAPACITY_SD_CARD_V2_0))   {     cardinfo->SD_csd.DeviceSize = (tmp & 0x03) SD_csd.DeviceSize |= (tmp) > 24);     cardinfo->SD_csd.DeviceSize |= (tmp & 0xC0) >> 6;     cardinfo->SD_csd.MaxRdCurrentVDDMin = (tmp & 0x38) >> 3;     cardinfo->SD_csd.MaxRdCurrentVDDMax = (tmp & 0x07);     //!< Byte 9 //     tmp = (u8)((CSD_Tab[2] & 0x00FF0000) >> 16);     cardinfo->SD_csd.MaxWrCurrentVDDMin = (tmp & 0xE0) >> 5;     cardinfo->SD_csd.MaxWrCurrentVDDMax = (tmp & 0x1C) >> 2;     cardinfo->SD_csd.DeviceSizeMul = (tmp & 0x03) > 8);     cardinfo->SD_csd.DeviceSizeMul |= (tmp & 0x80) >> 7;         cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;     cardinfo->CardCapacity /= (1 SD_csd.DeviceSizeMul + 2));     cardinfo->CardBlockSize = 1 SD_csd.RdBlockLen);     cardinfo->CardCapacity /= cardinfo->CardBlockSize;   }   else if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)   {     //!< Byte 7 //     tmp = (u8)(CSD_Tab[1] & 0x000000FF);     cardinfo->SD_csd.DeviceSize = (tmp & 0x3F) > 24);     cardinfo->SD_csd.DeviceSize |= (tmp > 16);     cardinfo->SD_csd.DeviceSize |= (tmp);     //!< Byte 10 //     tmp = (u8)((CSD_Tab[2] & 0x0000FF00) >> 8);         cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) / 512 / 1024;     cardinfo->CardBlockSize = 512;      }   cardinfo->SD_csd.EraseGrSize = (tmp & 0x40) >> 6;   cardinfo->SD_csd.EraseGrMul = (tmp & 0x3F) SD_csd.EraseGrMul |= (tmp & 0x80) >> 7;   cardinfo->SD_csd.WrProtectGrSize = (tmp & 0x7F);   //!< Byte 12 //   tmp = (u8)((CSD_Tab[3] & 0xFF000000) >> 24);   cardinfo->SD_csd.WrProtectGrEnable = (tmp & 0x80) >> 7;   cardinfo->SD_csd.ManDeflECC = (tmp & 0x60) >> 5;   cardinfo->SD_csd.WrSpeedFact = (tmp & 0x1C) >> 2;   cardinfo->SD_csd.MaxWrBlockLen = (tmp & 0x03) > 16);   cardinfo->SD_csd.MaxWrBlockLen |= (tmp & 0xC0) >> 6;   cardinfo->SD_csd.WriteBlockPaPartial = (tmp & 0x20) >> 5;   cardinfo->SD_csd.Reserved3 = 0;   cardinfo->SD_csd.ContentProtectAppli = (tmp & 0x01);   //!< Byte 14 //   tmp = (u8)((CSD_Tab[3] & 0x0000FF00) >> 8);   cardinfo->SD_csd.FileFormatGrouop = (tmp & 0x80) >> 7;   cardinfo->SD_csd.CopyFlag = (tmp & 0x40) >> 6;   cardinfo->SD_csd.PermWrProtect = (tmp & 0x20) >> 5;   cardinfo->SD_csd.TempWrProtect = (tmp & 0x10) >> 4;   cardinfo->SD_csd.FileFormat = (tmp & 0x0C) >> 2;   cardinfo->SD_csd.ECC = (tmp & 0x03);   //!< Byte 15 //   tmp = (u8)(CSD_Tab[3] & 0x000000FF);   cardinfo->SD_csd.CSD_CRC = (tmp & 0xFE) >> 1;   cardinfo->SD_csd.Reserved4 = 1;   //!< Byte 0 //   tmp = (u8)((CID_Tab[0] & 0xFF000000) >> 24);   cardinfo->SD_cid.ManufacturerID = tmp;   //!< Byte 1 //   tmp = (u8)((CID_Tab[0] & 0x00FF0000) >> 16);   cardinfo->SD_cid.OEM_AppliID = tmp > 8);   cardinfo->SD_cid.OEM_AppliID |= tmp;   //!< Byte 3 //   tmp = (u8)(CID_Tab[0] & 0x000000FF);   cardinfo->SD_cid.ProdName1 = tmp > 24);   cardinfo->SD_cid.ProdName1 |= tmp > 16);   cardinfo->SD_cid.ProdName1 |= tmp > 8);   cardinfo->SD_cid.ProdName1 |= tmp;   //!< Byte 7 //   tmp = (u8)(CID_Tab[1] & 0x000000FF);   cardinfo->SD_cid.ProdName2 = tmp;   //!< Byte 8 //   tmp = (u8)((CID_Tab[2] & 0xFF000000) >> 24);   cardinfo->SD_cid.ProdRev = tmp;   //!< Byte 9 //   tmp = (u8)((CID_Tab[2] & 0x00FF0000) >> 16);   cardinfo->SD_cid.ProdSN = tmp > 8);   cardinfo->SD_cid.ProdSN |= tmp SD_cid.ProdSN |= tmp > 24);   cardinfo->SD_cid.ProdSN |= tmp;   //!< Byte 13 //   tmp = (u8)((CID_Tab[3] & 0x00FF0000) >> 16);   cardinfo->SD_cid.Reserved1 |= (tmp & 0xF0) >> 4;   cardinfo->SD_cid.ManufactDate = (tmp & 0x0F) > 8);   cardinfo->SD_cid.ManufactDate |= tmp;   //!< Byte 15 //   tmp = (u8)(CID_Tab[3] & 0x000000FF);   cardinfo->SD_cid.CID_CRC = (tmp & 0xFE) >> 1;   cardinfo->SD_cid.Reserved2 = 1;  详情 回复 发表于 2012-9-12 13:36
点赞 关注
 

回复
举报

4005

帖子

0

TA的资源

版主

沙发
 
要16进显示
此帖出自stm32/stm8论坛

点评

我用16进制显示是0E,那请问SD卡的容量是0E是什么意思呢?  详情 回复 发表于 2012-9-11 15:11
 
 

回复

4

帖子

0

TA的资源

一粒金砂(初级)

板凳
 

回复 沙发 huo_hu 的帖子

我用16进制显示是0E,那请问SD卡的容量是0E是什么意思呢?
此帖出自stm32/stm8论坛

点评

自己看吧 //!< Byte 0 // tmp = (u8)((CSD_Tab[0] & 0xFF000000) >> 24); cardinfo->SD_csd.CSDStruct = (tmp & 0xC0) >> 6; cardinfo->SD_csd.SysSpecVersion = (tmp & 0x3C) >> 2; cardinfo->SD  详情 回复 发表于 2012-9-12 13:36
 
 

回复

4005

帖子

0

TA的资源

版主

4
 

回复 板凳 dianziyn 的帖子

自己看吧

  //!< Byte 0 //
  tmp = (u8)((CSD_Tab[0] & 0xFF000000) >> 24);
  cardinfo->SD_csd.CSDStruct = (tmp & 0xC0) >> 6;
  cardinfo->SD_csd.SysSpecVersion = (tmp & 0x3C) >> 2;
  cardinfo->SD_csd.Reserved1 = tmp & 0x03;

  //!< Byte 1 //
  tmp = (u8)((CSD_Tab[0] & 0x00FF0000) >> 16);
  cardinfo->SD_csd.TAAC = tmp;

  //!< Byte 2 //
  tmp = (u8)((CSD_Tab[0] & 0x0000FF00) >> 8);
  cardinfo->SD_csd.NSAC = tmp;

  //!< Byte 3 //
  tmp = (u8)(CSD_Tab[0] & 0x000000FF);
  cardinfo->SD_csd.MaxBusClkFrec = tmp;

  //!< Byte 4 //
  tmp = (u8)((CSD_Tab[1] & 0xFF000000) >> 24);
  cardinfo->SD_csd.CardComdClasses = tmp << 4;

  //!< Byte 5 //
  tmp = (u8)((CSD_Tab[1] & 0x00FF0000) >> 16);
  cardinfo->SD_csd.CardComdClasses |= (tmp & 0xF0) >> 4;
  cardinfo->SD_csd.RdBlockLen = tmp & 0x0F;
  
  //!< Byte 6 //
  tmp = (u8)((CSD_Tab[1] & 0x0000FF00) >> 8);
  cardinfo->SD_csd.PartBlockRead = (tmp & 0x80) >> 7;
  cardinfo->SD_csd.WrBlockMisalign = (tmp & 0x40) >> 6;
  cardinfo->SD_csd.RdBlockMisalign = (tmp & 0x20) >> 5;
  cardinfo->SD_csd.DSRImpl = (tmp & 0x10) >> 4;
  cardinfo->SD_csd.Reserved2 = 0; //!< Reserved //

  if ((CardType == SDIO_STD_CAPACITY_SD_CARD_V1_1) || (CardType == SDIO_STD_CAPACITY_SD_CARD_V2_0))
  {
    cardinfo->SD_csd.DeviceSize = (tmp & 0x03) << 10;

    //!< Byte 7 //
    tmp = (u8)(CSD_Tab[1] & 0x000000FF);
    cardinfo->SD_csd.DeviceSize |= (tmp) << 2;

    //!< Byte 8 //
    tmp = (u8)((CSD_Tab[2] & 0xFF000000) >> 24);
    cardinfo->SD_csd.DeviceSize |= (tmp & 0xC0) >> 6;

    cardinfo->SD_csd.MaxRdCurrentVDDMin = (tmp & 0x38) >> 3;
    cardinfo->SD_csd.MaxRdCurrentVDDMax = (tmp & 0x07);

    //!< Byte 9 //
    tmp = (u8)((CSD_Tab[2] & 0x00FF0000) >> 16);
    cardinfo->SD_csd.MaxWrCurrentVDDMin = (tmp & 0xE0) >> 5;
    cardinfo->SD_csd.MaxWrCurrentVDDMax = (tmp & 0x1C) >> 2;
    cardinfo->SD_csd.DeviceSizeMul = (tmp & 0x03) << 1;
    //!< Byte 10 //
    tmp = (u8)((CSD_Tab[2] & 0x0000FF00) >> 8);
    cardinfo->SD_csd.DeviceSizeMul |= (tmp & 0x80) >> 7;
   
    cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) ;
    cardinfo->CardCapacity /= (1 << (cardinfo->SD_csd.DeviceSizeMul + 2));
    cardinfo->CardBlockSize = 1 << (cardinfo->SD_csd.RdBlockLen);
    cardinfo->CardCapacity /= cardinfo->CardBlockSize;
  }
  else if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
  {
    //!< Byte 7 //
    tmp = (u8)(CSD_Tab[1] & 0x000000FF);
    cardinfo->SD_csd.DeviceSize = (tmp & 0x3F) << 16;

    //!< Byte 8 //
    tmp = (u8)((CSD_Tab[2] & 0xFF000000) >> 24);

    cardinfo->SD_csd.DeviceSize |= (tmp << 8);

    //!< Byte 9 //
    tmp = (u8)((CSD_Tab[2] & 0x00FF0000) >> 16);

    cardinfo->SD_csd.DeviceSize |= (tmp);

    //!< Byte 10 //
    tmp = (u8)((CSD_Tab[2] & 0x0000FF00) >> 8);
   
    cardinfo->CardCapacity = (cardinfo->SD_csd.DeviceSize + 1) / 512 / 1024;
    cardinfo->CardBlockSize = 512;   
  }

  cardinfo->SD_csd.EraseGrSize = (tmp & 0x40) >> 6;
  cardinfo->SD_csd.EraseGrMul = (tmp & 0x3F) << 1;

  //!< Byte 11 //
  tmp = (u8)(CSD_Tab[2] & 0x000000FF);
  cardinfo->SD_csd.EraseGrMul |= (tmp & 0x80) >> 7;
  cardinfo->SD_csd.WrProtectGrSize = (tmp & 0x7F);

  //!< Byte 12 //
  tmp = (u8)((CSD_Tab[3] & 0xFF000000) >> 24);
  cardinfo->SD_csd.WrProtectGrEnable = (tmp & 0x80) >> 7;
  cardinfo->SD_csd.ManDeflECC = (tmp & 0x60) >> 5;
  cardinfo->SD_csd.WrSpeedFact = (tmp & 0x1C) >> 2;
  cardinfo->SD_csd.MaxWrBlockLen = (tmp & 0x03) << 2;

  //!< Byte 13 //
  tmp = (u8)((CSD_Tab[3] & 0x00FF0000) >> 16);
  cardinfo->SD_csd.MaxWrBlockLen |= (tmp & 0xC0) >> 6;
  cardinfo->SD_csd.WriteBlockPaPartial = (tmp & 0x20) >> 5;
  cardinfo->SD_csd.Reserved3 = 0;
  cardinfo->SD_csd.ContentProtectAppli = (tmp & 0x01);

  //!< Byte 14 //
  tmp = (u8)((CSD_Tab[3] & 0x0000FF00) >> 8);
  cardinfo->SD_csd.FileFormatGrouop = (tmp & 0x80) >> 7;
  cardinfo->SD_csd.CopyFlag = (tmp & 0x40) >> 6;
  cardinfo->SD_csd.PermWrProtect = (tmp & 0x20) >> 5;
  cardinfo->SD_csd.TempWrProtect = (tmp & 0x10) >> 4;
  cardinfo->SD_csd.FileFormat = (tmp & 0x0C) >> 2;
  cardinfo->SD_csd.ECC = (tmp & 0x03);

  //!< Byte 15 //
  tmp = (u8)(CSD_Tab[3] & 0x000000FF);
  cardinfo->SD_csd.CSD_CRC = (tmp & 0xFE) >> 1;
  cardinfo->SD_csd.Reserved4 = 1;


  //!< Byte 0 //
  tmp = (u8)((CID_Tab[0] & 0xFF000000) >> 24);
  cardinfo->SD_cid.ManufacturerID = tmp;

  //!< Byte 1 //
  tmp = (u8)((CID_Tab[0] & 0x00FF0000) >> 16);
  cardinfo->SD_cid.OEM_AppliID = tmp << 8;

  //!< Byte 2 //
  tmp = (u8)((CID_Tab[0] & 0x000000FF00) >> 8);
  cardinfo->SD_cid.OEM_AppliID |= tmp;

  //!< Byte 3 //
  tmp = (u8)(CID_Tab[0] & 0x000000FF);
  cardinfo->SD_cid.ProdName1 = tmp << 24;

  //!< Byte 4 //
  tmp = (u8)((CID_Tab[1] & 0xFF000000) >> 24);
  cardinfo->SD_cid.ProdName1 |= tmp << 16;

  //!< Byte 5 //
  tmp = (u8)((CID_Tab[1] & 0x00FF0000) >> 16);
  cardinfo->SD_cid.ProdName1 |= tmp << 8;

  //!< Byte 6 //
  tmp = (u8)((CID_Tab[1] & 0x0000FF00) >> 8);
  cardinfo->SD_cid.ProdName1 |= tmp;

  //!< Byte 7 //
  tmp = (u8)(CID_Tab[1] & 0x000000FF);
  cardinfo->SD_cid.ProdName2 = tmp;

  //!< Byte 8 //
  tmp = (u8)((CID_Tab[2] & 0xFF000000) >> 24);
  cardinfo->SD_cid.ProdRev = tmp;

  //!< Byte 9 //
  tmp = (u8)((CID_Tab[2] & 0x00FF0000) >> 16);
  cardinfo->SD_cid.ProdSN = tmp << 24;

  //!< Byte 10 //
  tmp = (u8)((CID_Tab[2] & 0x0000FF00) >> 8);
  cardinfo->SD_cid.ProdSN |= tmp << 16;

  //!< Byte 11 //
  tmp = (u8)(CID_Tab[2] & 0x000000FF);
  cardinfo->SD_cid.ProdSN |= tmp << 8;

  //!< Byte 12 //
  tmp = (u8)((CID_Tab[3] & 0xFF000000) >> 24);
  cardinfo->SD_cid.ProdSN |= tmp;

  //!< Byte 13 //
  tmp = (u8)((CID_Tab[3] & 0x00FF0000) >> 16);
  cardinfo->SD_cid.Reserved1 |= (tmp & 0xF0) >> 4;
  cardinfo->SD_cid.ManufactDate = (tmp & 0x0F) << 8;

  //!< Byte 14 //
  tmp = (u8)((CID_Tab[3] & 0x0000FF00) >> 8);
  cardinfo->SD_cid.ManufactDate |= tmp;

  //!< Byte 15 //
  tmp = (u8)(CID_Tab[3] & 0x000000FF);
  cardinfo->SD_cid.CID_CRC = (tmp & 0xFE) >> 1;
  cardinfo->SD_cid.Reserved2 = 1;
此帖出自stm32/stm8论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表