新聞中心

        SD卡讀CID寄存器

        作者: 時(shí)間:2016-11-10 來(lái)源:網(wǎng)絡(luò) 收藏
        /**

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

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

        /**************************************************************************************
        * FunctionName : SD_GetCIDRegister()
        * Description : 讀CID寄存器,寄存器長(zhǎng)度為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--; // 等待超時(shí)
        }

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

        SD_ReadByte(); // 讀CRC
        SD_ReadByte();

        rvalue = SD_RESPONSE_NO_ERROR; // 設(shè)置成功標(biāo)志
        }

        SD_Enable(1); // 清除SD卡片選
        SD_WriteByte(0xFF); // 8個(gè)時(shí)鐘脈沖的延遲

        // 把獲取值放入CID結(jié)構(gòu)體中
        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;
        }



        關(guān)鍵詞: SD卡讀CID寄存

        評(píng)論


        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 宜都市| 论坛| 通道| 湘潭市| 红桥区| 台东县| 来宾市| 新巴尔虎左旗| 扎鲁特旗| 三门县| 洛扎县| 阿坝| 玉山县| 大足县| 巫山县| 高要市| 钟山县| 苍山县| 长泰县| 宣化县| 门头沟区| 江城| 弥勒县| 新宁县| 盐山县| 郁南县| 乐清市| 嘉荫县| 寻甸| 庆元县| 神木县| 磐石市| 墨玉县| 扬州市| 神农架林区| 巴中市| 大关县| 延安市| 曲麻莱县| 卢龙县| 普陀区|