新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > SD卡讀CID寄存器

SD卡讀CID寄存器

作者: 時間:2016-11-10 來源:網(wǎng)絡 收藏
/**

* @brief Card Identification Data: CID Register
*/
typedef struct
{
uint8 ManufacturerID; // 生產(chǎn)標識ID
uint16 OEM_AppliID; // OEM/應用 ID
uint32 ProdName1; // 產(chǎn)品名稱1
uint8 ProdName2; // 產(chǎn)品名稱2
uint8 ProdRev; // 產(chǎn)品版本
uint32 ProdSN; // 產(chǎn)品序號
uint8 Reserved1; // 保留
uint16 ManufactDate; // 生產(chǎn)日期
uint8 CID_CRC; // CID CRC
uint8 Reserved2; // always 1
} SD_CID;

本文引用地址:http://www.2s4d.com/article/201611/317388.htm

/**************************************************************************************
* FunctionName : SD_GetCIDRegister()
* Description : 讀CID寄存器,寄存器長度為128,16字節(jié)
* EntryParameter : cid - 寄存器
* ReturnValue : 返回操作狀態(tài):成功-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) // 等待數(shù)據(jù)接收開始,收到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寄存

評論


技術專區(qū)

關閉