TXT

CID

By Hazel Shaw,2014-12-04 10:38
14 views 0
CID

    SD???ÁCID?Ä?æÆ? 2011-06-13 14:36:10| ?ÖÀà?º ?ª??Ó?Óà | ?êÇ??º |×ÖºÅ?ó

    ÖÐ

    Ð? ??ÔÄ

    /**

     * @brief Card Identification Data: CID Register

     */

    typedef struct

    {

     unsigned char ManufacturerID; // Éú?ú?êÊ?ID

     unsigned short OEM_AppliID; // OEM/Ó?ÓÃ ID

     unsigned int ProdName1; // ?úÆ?Ãû?Æ1

     unsigned char ProdName2; // ?úÆ?Ãû?Æ2

     unsigned char ProdRev; // ?úÆ??æ??

     unsigned int ProdSN; // ?úÆ?ÐòºÅ

     unsigned char Reserved1; // ??Áô

     unsigned short ManufactDate; // Éú?úÈÕÆÚ

     unsigned char CID_CRC; // CID CRC

     unsigned char Reserved2; // always 1 } SD_CID;

    /**************************************************************************************

    * FunctionName : SD_GetCIDRegister()

    * Description : ?ÁCID?Ä?æÆ????Ä?æÆ????ÈΪ128??16×Ö?Ú * EntryParameter : cid - ?Ä?æÆ?

    * ReturnValue : ?µ?Ø?Ù×?×?Ì??º?É??-0

    **************************************************************************************/

    unsigned char SD_GetCIDRegister(SD_CID *cid)

    {

     unsigned char i;

     unsigned char cidTable[16];

     unsigned char count = 0xFF;

     unsigned char 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;

    }

Report this document

For any questions or suggestions please email
cust-service@docsford.com