新闻中心

EEPW首页>嵌入式系统>设计应用> SD卡读CID寄存器

SD卡读CID寄存器

作者: 时间:2016-11-10 来源:网络 收藏
/**

* @brief Card Identification Data: CID Register
*/
typedef struct
{
uint8 ManufacturerID; // 生产标识ID
uint16 OEM_AppliID; // OEM/应用 ID
uint32 ProdName1; // 产品名称1
uint8 ProdName2; // 产品名称2
uint8 ProdRev; // 产品版本
uint32 ProdSN; // 产品序号
uint8 Reserved1; // 保留
uint16 ManufactDate; // 生产日期
uint8 CID_CRC; // CID CRC
uint8 Reserved2; // always 1
} SD_CID;

本文引用地址://m.amcfsurvey.com/article/201611/317388.htm

/**************************************************************************************
* FunctionName : SD_GetCIDRegister()
* Description : 读CID寄存器,寄存器长度为128,16字节
* EntryParameter : cid - 寄存器
* ReturnValue : 返回操作状态:成功-0
**************************************************************************************/
uint8 SD_GetCIDRegister(SD_CID *cid)
{
uint8 i;
uint8 cidTable[16];
uint8 count = 0xFF;
uint8 rvalue = SD_RESPONSE_FAILURE; // 返回值

SD_Enable(0); // SD卡使能

if (SD_SendCmd(CMD10,0x00,0xFF) == SD_RESPONSE_NO_ERROR)
{
while ((SD_ReadByte() != SD_START_SINGLE_BLOCK_READ) && count) // 等待数据接收开始,收到0xFE表示开始
{
count--; // 等待超时
}

if (count != 0x00)
{
for (i=0; i<16; i++)
{
cidTable[i] = SD_ReadByte();
}
}

SD_ReadByte(); // 读CRC
SD_ReadByte();

rvalue = SD_RESPONSE_NO_ERROR; // 设置成功标志
}

SD_Enable(1); // 清除SD卡片选
SD_WriteByte(0xFF); // 8个时钟脉冲的延迟

// 把获取值放入CID结构体中
cid->ManufacturerID = cidTable[0]; // Byte 0
cid->OEM_AppliID = cidTable[1] << 8; // Byte 1
cid->OEM_AppliID |= cidTable[2]; // Byte 2
cid->ProdName1 = cidTable[3] << 24; // Byte 3
cid->ProdName1 |= cidTable[4] << 16; // Byte 4
cid->ProdName1 |= cidTable[5] << 8; // Byte 5
cid->ProdName1 |= cidTable[6]; // Byte 6
cid->ProdName2 = cidTable[7]; // Byte 7
cid->ProdRev = cidTable[8]; // Byte 8
cid->ProdSN = cidTable[9] << 24; // Byte 9
cid->ProdSN |= cidTable[10] << 16; // Byte 10
cid->ProdSN |= cidTable[11] << 8; // Byte 11
cid->ProdSN |= cidTable[12]; // Byte 12
cid->Reserved1 |= (cidTable[13] & 0xF0) >> 4; // Byte 13
cid->ManufactDate = (cidTable[13] & 0x0F) << 8; // Byte 14
cid->ManufactDate |= cidTable[14]; // Byte 15
cid->CID_CRC = (cidTable[15] & 0xFE) >> 1;
cid->Reserved2 = 1;

return rvalue;
}



关键词:SD卡读CID寄存

评论


技术专区

关闭