read 4G SDHC card using DRM104SW modified

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

read 4G SDHC card using DRM104SW modified

1,621 Views
SDcardreader
Contributor I

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

Labels (1)
0 Kudos
1 Reply

269 Views
protoease
Contributor II

I have the same question.  I specifically bought the DEMOFLEXISJMSD so that I could get SD and SDHC card support working without wondering about hardware, but it is obvious that the firmware (DRM104SW) doesn't support SDHC cards, only the standard SD.

 

I would think it possible for the software to be modified/updated easily based on the following on the ELM FatFs webpage:

 

How to support SDC Ver2 and high capacity cards

After the card enters idle state with a CMD0, send a CMD8 with argument of 0x000001AA and correct CRC prior to initialization process. When the CMD8 is rejected with an illigal command error (0x05), the card is SDC V1 or MMC. When the CMD8 is accepted, R7 response (R1(0x01) and trailing 32 bit data) will be returned. The lower 12 bits in the return value 0x1AA means that the card is SDC V2 and it can work at voltage range of 2.7 to 3.6 volts. If not the case, the card must be rejected. And then initiate initialization with ACMD41 with HCS (bit 30). After the initialization completed, read OCR and check CCS (bit 30) in the OCR. When it is set, subsequent data read/write operations that described below are commanded in block address insted of byte address. The block size is always fixed to 512 bytes.

 

It seems that the only difference is the size reading and block addressing, unless the SDHC cards don't support SPI/MMC interfacing (which some have said - some makes/models only support SD interface)

 

I'm going to try modifying the source for DRM104SW.

 

0 Kudos