zhu bieming

read 4G SDHC card using DRM104SW modified

Discussion created by zhu bieming on Jun 22, 2010
Latest reply on Jan 29, 2011 by protoease

Hi,everybody!Now  I have  successfully read 2G Standard SD card using DRM104SW,so I want to read 4G SDHC card.My SD initialize flow as fellow:

 CMD0==>CMD8==>CMD1

But I cannot read the 4G SDHC card.

 

UINT8 SD_Init(void) 

{     UINT8 temp[5];    

       SPI_Init();             // SPI Initialization


       SPI_SS=ENABLE;  

       SD_CLKDelay(10);            // Send 80 clocks   

       SPI_SS=DISABLE;      

       gu8SD_Argument.lword=0;    

       SD_CLKDelay(8);              /* IDLE Command */        

       SPI_SS=ENABLE;       

      if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))  

     {        SPI_SS=DISABLE;      

               return(1);      // Command IDLE fail  

     }  

      SPI_SS=DISABLE;      

      (void)SPI_Receive_byte();  // Dummy SPI cycle     //SD card specifical 2.0  

 

       strcpy(temp, SD_Send_Cmd8(8));  

       if(temp[4] != 0xAA || temp[3] != 0x01) 

      {      

             //return (2);    

      }                            

      (void)SPI_Receive_byte();  // Dummy SPI cycle
              /*  Initialize SD Command */    

      SPI_SS=ENABLE;  

     gu8SD_Argument.lword = CMD1_V2_Parameter;     

     while(SD_SendCommand(SD_CMD1|0x40,SD_OK));  

     SPI_SS=DISABLE;      

     (void)SPI_Receive_byte();  // Dummy SPI cycle
    /*  Block Length */    

    SPI_SS=ENABLE;            

    gu8SD_Argument.lword=SD_BLOCK_SIZE;  

   if(SD_SendCommand(SD_CMD16|0x40,SD_OK))  

   {        

            SPI_SS=DISABLE;      

            return(1);      // Command IDLE fail 

   }        

   SPI_SS=DISABLE;         

   SPI_High_rate();        

   SPI_Send_byte(0x00); 

   SPI_Send_byte(0x00);    

  //(void)SPI_Receive_byte();  // Dummy SPI cycle    

  return(0);

}

 

// cmd8 when SDHC(SD2.0) before send CMD1 to initialize command

UINT8 * SD_Send_Cmd8(UINT8 cmd)

{

UINT8 response[4] ;

 

UINT8 retry=0;

 

 

SPI_Send_byte(0xff); 

 

SPI_SS=ENABLE;          

 

 

SPI_Send_byte(cmd | 0x40);

SPI_Send_byte(0x00);

SPI_Send_byte(0x00);

SPI_Send_byte(0x01);

SPI_Send_byte(0xAA);

  SPI_Send_byte(0x87);

 

while((response[0] = SPI_Receive_byte())&0x04 != 0x00);

 

   response[1] = SPI_Receive_byte();

   response[2] = SPI_Receive_byte();

   response[3] = SPI_Receive_byte();

   response[4] = SPI_Receive_byte();

 

   (void)SPI_Receive_byte();

 

    // if(retry++ > 200) break;

 

SPI_SS=DISABLE;

 

// SPI_SendByte(0xff); 

 

return response;

}

 

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

UINT8 SD_Read_Block(UINT32 u16SD_Block,UINT8 *pu8DataPointer) 

{

    UINT8 u8Temp=0;

    UINT16 u16Counter;

 

    SPI_SS=ENABLE;

 

    gu8SD_Argument.lword=u16SD_Block;

   // gu8SD_Argument.lword=gu8SD_Argument.lword<< SD_BLOCK_SHIFT;       //for 2G or below

 

    if(SD_SendCommand(SD_CMD17|0x40,SD_OK))

    {

        SPI_SS=DISABLE;

        return(4);      // Command IDLE fail

    }

 

    while(u8Temp!=0xFE)

        u8Temp=SPI_Receive_byte();

 

    for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++)

        *pu8DataPointer++=SPI_Receive_byte();

 

    (void)SPI_Receive_byte();  // Dummy SPI cycle

    (void)SPI_Receive_byte();  // Dummy SPI cycle

 

    SPI_SS=DISABLE;

 

    (void)SPI_Receive_byte();  // Dummy SPI cycle

 

    return(0);

}

 

Any suggestion and help will be appreciated!

Regards,

Micael

Outcomes