Because of the holidays, TI E2E™ design support forum responses will be delayed from Dec. 25 through Jan. 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem in initialization of micro sd card(16GB)

Other Parts Discussed in Thread: CC2541, MSP430F5529

Hi all,

        Can anybody please tell me what should be the initialization sequence of micro sd card above 2GB? I am new to this forum and my mcu is cc2541 and not msp430 series but i am using sample code of sd card interfacing with msp430 provided at

I have ported my hardware based on this sample code. I am able to read and write data into micro sd card(2GB) but not able to interface 16GB card. I have gone through several posts related to this topic on ti forum as well as non-ti. I have found common answer to this problem as we need to change the initialization command i.e.CMD1 needs to be replaced with cmd55 followed by ACMD41. I have tried with following sequence

// set MMC in Idle mode
char mmcGoIdle()
{
  char response=0x01;
  CS_LOW();

  //Send Command 0 to put MMC in SPI mode
  mmcSendCmd(MMC_GO_IDLE_STATE,0,0x95);
  //Now wait for READY RESPONSE
  if(mmcGetResponse()!=0x01)
    return MMC_INIT_ERROR;

  while(response!=0x00)                                   //modified to wait until micro sd card is ready for read and write
  {
    CS_HIGH();
    spiSendByte(DUMMY_CHAR);
    CS_LOW();
    //mmcSendCmd(MMC_SEND_OP_COND,0x00,0xff);                                    //uncomment this line to interface 2GB card
    mmcSendCmd(0x77,0x00,0xff);           //cmd55                                                 //comment this line to interface 2GB card
    mmcSendCmd(0x69,0x00,0xff);           //ACMD41                                              //comment this line to interface 2GB card
    response=mmcGetResponse();
  }
  CS_HIGH();
  spiSendByte(DUMMY_CHAR);
  return (MMC_SUCCESS);
}

Most probably there is problem in sending this cmd55 and ACMD41. May be CRC byte be wrong.

Can anyone please help me out in troubleshooting this problem?

I want to know what changes i need to do to interface card>2GB in the original sample code provided for msp430?

thanks

  • Hi all, can anyone please suggest me what should be sequence for initializing & crc value for 16GB micro sd card?
  • Can anybody please tell me what does 'x' corresponds to in CRC7 calculation? section 4.5

    Generator polynomial: G(x) = x^7+ x^3+ 1.

    M(x) = (first bit) * x^n+ (second bit) * x^n-1+...+ (last bit) * x^0

    CRC[6...0] = Remainder [(M(x) * x^7)/G(x)]

    I am facing problem in getting initialization of sandisk 16GB micro sd card. I want to know CRC value of CMD55 & ACMD41 in mmcSendCmd(0x69,0x00,0xff);  

    thanks

  • Hi Kumar,

    Let me look into this. Could you please give us more information on which HW are you using?? For example, MSP430 Launch Pad + a SD Card booster pack??

    Also which MSP430 derivate are you using??

    Thanks,

    David
  • Thanks David for taking care into the post.
    As i had mentioned in my first post, I am not using any MSP430 based HW. In stead i am using customized CC2541 readymade module. I have ported similar to MSP430 registers. If i use 2GB micro sd card then i am able to write and read data correctly but 16GB micro sd card is not getting initialized. I am not getting 0x00 response for ACMD41 command while using 16GB card although i am following the procedure for sd card initialization discussed in lots of e2e forums and google also. I doubt if crc sequence is correct. I always get "response = 0xff" as response for ACMD41 for
    while(response!=0x00)
    {
    .
    .
    } and it becomes infinite loop

  • Hi Kumar,

    That's what I thought and just wanted to be sure. Let me run a few test on my side (msp430) and I'll get back to you as soon as I can read/initialize a 16GB SD card correctly.

    Thanks,

    David
  • Hi David,
    So nice of you. I am waiting for your response. By that time i will also try to troubleshoot this problem.
    Regards
    Kumar
  • Hi David,
    Did you had test for interfacing 16GB micro sd card with your msp430 hardware? Even after several try i couldn't figure out the problem in initialization. I am waiting for your response.
    In the mean time i had tried interfacing 16GB micro sd card using chan's FAT file system and i am able to read and write data into it. But problem is that i can't understand fully the logic behind FAT file system specially file handling. If i could interface using sample code provided for MSP430 then it will be too much helpful for me to understand. That's why i am waiting for your response.
    Despite this, does TI provide sample code for implementing FAT system on any hardware platform?
    Regards
    Kumar
  • Hi Kumar,

    Yes we have a sample code. It is for the msp430f5529, but you should be able to re-use it.

    Please take a look at the MSP-EXP430F5529 User Experience Project in dev.ti.com/.../

    And let me know if you have further questions.

    Best regards,

    David
  • Hi David,
    1)Thanks for providing reference of sample code example for MP430 but that doesn't include any example code for sd card interfacing. I can't find any such example in your referred link.
    2)Did you had test for interfacing 16GB sd card without using file system? As i had told i am able to access sd card using chan's FATFS but i am facing some problem related to low data storage in RAM and due to continuous opening and closing of file in sd card. Either i will have to leave FATFS concept or will need to use some other controller. So i want to have a test without using FATFS. I had tried a lot but couldn't interface 16GB sd card using sample code provided for MSP430
  • Hi Kumar,

    kumar singh said:
    1)Thanks for providing reference of sample code example for MP430 but that doesn't include any example code for sd card interfacing. I can't find any such example in your referred link.

    I think it will be easier if you download the UE demo from here:

    http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP-EXP430F5529/latest/index_FDS.html

    kumar singh said:
    2)Did you had test for interfacing 16GB sd card without using file system?

    For the 16 GB sd card, I've only used the FS in the UE Demo. At the same time I'm wondering if you have seen this App Note  - MSP with SD: http://www.ti.com/.../slaa281b.pdf

     Please let me know if this is the code that you are having problems with.

     Thanks,

      David

  • Hi David,
    In the link i found similar Chan's FATFS firmware of interfacing sd card what i am using and what i had tested earlier. Using FATFS i have already been able to interface different storage size micro sd card. Anyway thanks for providing the link for UE Demo.

    Ya i was having problem with the same firmware provided at www.ti.com/.../slaa281b.htm Problem is only in initialization of 16GB micro sd card(sending ACMD41 and getting correct response) although i had no problem in initialization of 2GB micro sd card. May be i would be sending wrong sequence for initialization(ACMD41) as mentioned in my first post.
    thanks
  • Hi Kumar,

    I'm trying to get SD card running with CC2541. I've problem in intialization. I have setup SPI USART1 Alternate 2 function as follows.

    void SPI_init(uint8 baud_E, uint8 baud_M)
    {

    /****************************************************************************
    *
    * Port pins used by USART 1 Alt 2 operating in SPI mode are
    * MISO = P1_7
    * MOSI = P1_6
    * SCK = P1_5
    * SSN = P1_4
    * Set SPI Mode 0 or 3 according to Chan's guide

    */

    //*** Configure USART 1 SPI at alternate location 2 ***
    /* IO Port PERCFG Register
    * 7 = Reserved
    * 6 = T1CFG = 0
    * 5 = T3CFG = 0
    * 4 = T4CFG = 0
    * 3:2= Reserved
    * 1 = U1CFG = 1
    * 0 = U0CFG = 0
    */
    PERCFG |= 0x02;

    // Peripheral function on SCK, MISO and MOSI (P1_5-7)
    P1SEL = 0xE0;

    // Configure CS (P1_4) as output
    P1DIR |= 0x10;
    CS = CS_DISABLED; /*CS_DISABLED =1*/

    /* Give UART1 priority over Timer3. */
    //P2SEL &= ~0x20;

    //*** Setup the SPI interface ***
    U1CSR = 0x00; // USART 1 = SPI master mode. SD card is slave

    // Negative clock polarity, Phase: data out on CPOL -> CPOL-inv
    // data in on CPOL-inv -> CPOL
    // MSB first
    U1GCR = 0x20;

    // SCK frequency = 230KHz
    // Put decimal values in formula for baud rate generation and you will get around 230KHz
    U1GCR |= baud_E; // 0x0C; // BAUD_E XXX_ ____ 4:0 Decimal = 12
    U1BAUD = baud_M; // 0xD8; // BAUD_M 7:0 Decimal = 216

    /* SCK frequency = 307.617 KHz
    U1GCR |= 0x0D; // BE =13
    U1BAUD = 0x3B; // BM =59
    */

    /*
    WAIT_1MS();
    WAIT_1MS();
    */
    //acc_initialized = TRUE;
    }

    and the SDInit function is as follows

    BYTE SDInit()
    {
    unsigned int CardStatus; // R2 value from status inquiry
    unsigned int Count;
    uint8 CardType;
    BYTE response = 0x00;

    /* Setup SPI mostly with 400KHz*/
    SPI_init(0x0C, 0xD8); // 230KHz

    /* Disable CS */
    CS = CS_ENABLED;

    /* fill send data with all ones - 80 bits long to */
    /* establish link with SD card this fulfills the */
    /* 74 clock cycle requirement... */
    for(Count=0;Count<10;Count++)
    spiWriteByte(0xFF);

    /* Enable CS */
    // CS = CS_ENABLED; /* Enable = 0 meaning selecting the SD card*/

    // This count represents one second. So We will try for one second to enter into ideal mode.
    Count = 1000;

    /* Set SD card in IDLE Mode */
    // Send a CMD0 with CS low to reset the card
    do
    {
    //WAIT_1MS();
    SD_Command( CMD_GO_IDLE_STATE, 0 );
    response = SD_GetR1();

    } while((response != 0x00)); // Removed Count, will loop forever untill i get 00

    CardType = 0;
    /*
    SD_Command(IDLE,0);
    if (SD_GetR1() != 0x01)
    return Success;
    */


    /* timeout if we never made it to IDLE state...
    if( !Count )
    return( SD_TIME_OUT );*/

    /* Initialization */
    Count = 2000; // two seconds...
    SD_Command( ACMD_SEND_OP_COND, 0 );

    if( SD_GetR1() <= 1 )
    {
    CardType = 2;
    }
    else
    {
    CardType = 1;
    }

    /* wait for initialization to finish... */
    do
    {
    //Delay(1);
    if( CardType == 2 )
    {
    SD_Command( CMD_APP_CMD, 0 );
    SD_Command( ACMD_SEND_OP_COND, 0 );
    }
    else
    {
    SD_Command( CMD_SEND_OP_COND, 0 );
    }
    } while(SD_GetR1() && --Count);

    /*
    if( !Count )
    return( SD_TIME_OUT ); */

    /* QUERY CARD STATUS...*/
    SD_Command( CMD_SEND_STATUS, 0 );
    CardStatus = SD_GetR2();

    if( CardStatus )
    return( 1 );

    /* SET BLOCK SIZE... */
    SD_Command( CMD_SET_BLOCKLEN, 512 );

    /* Switch to higher SPI speed*/

    /* Disable the card */
    CS = CS_DISABLED;

    return(0); // Success
    }

    I'm always getting 0x01 response. I'm using SDHC card of 4 GB. Any suggestions.

  • Hi Spandan,
    As i had told earlier, i also couldn't communicate with sd card>2GB capacity although <2GB works well. There is difference in initialization sequence of <2GB card and >2GB card. The initialization sequence for >2GB card needs ACMD41 command as explained in sd card reference manual. So there is problem in initialization using this command. i had tried a lot but couldn't succeed.
    regards
    kumar
  • Is this debug effort still ongoing?? If yes, could you please follow up, otherwise, Iwill close this thread (you can reopen it later if needed).

    Thanks,

    David
  • Hi David,
    I am sorry. Right now i am not working on this topic due to getting involved in some other work. You can surely close this thread. i will reopen it when i will be working on this topic and post resolution if my problem is troubleshooted.
    Regards
    Kumar

**Attention** This is a public forum