您的位置 首页 系统

SD卡读CID寄存器

/***@briefCardIdentificationData:CIDRegister*/typedefstruct{uint8ManufacturerID;//生产标识IDuint16OE…

/**

* @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;

/**************************************************************************************
* 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;
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qianrushi/xitong/275963.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部