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.

SPI interface of micro SD card in TMS570LS04x HDK

I have TMS570LS04x HDK and I want to use SD card slot available on board to perform read/write operation on card.

Is there any example code available for SPI interface of micro SD card in TMS570LS04x HDK ?

while searching the forum i found below wiki link for example code but the page is deleted.

http://processors.wiki.ti.com/index.php/TMS570LS04x_HDK_Kit

  • Swapnil,

    There was a "cleanup" done to the wiki pages recently and may have cleaned up more than it should have. I will look for this example code project and see if I can upload it to this forum post.

    Regards, Sunil

  • Hi Swapnil,

    We have a simple code for SD card connectivity test. The test is only send command to reset the card and read the ID back using SPI2. We don't have sample code to write/read data or file to/from the SD card.

    Regards,

    QJ

  • Could you pls provide the configuration for all SPI2 registers?  if PINMUX register should be configurated? In my project, only CMD0 is responsed with 0x01, then all response are all 0xFF.  

    I also noticed Spi->SPIBUF->LCSNR is 0x02 after reception,  it should be the copy of CSNR, but in fact CSNR is 0xFE,  CS0 is used.   i am puzzled.

  • Hi Yanfang,

    Attached please find the the SPI configuration file, and sdcard access files for the connectivity test. 

    4377.spi.c

    6131.SDCard.c0363.SDCard.h

    Regards,

    QJ

  • thank you very much, but i have some question about these source files:

     1. configuration about port direction: CS[1] is cofigurated as INPUT, not OUTPUT, so i think CS[0] is the chip selection for SD Card Slave SPI.  SOMI is configurated as INPUT, i think it is not correct.

       /** - SPI2 Port direction */
        spiREG2->PCDIR  =  1         /* SCS[0] */
                        | (0 << 1)   /* SCS[1] */   // CS1 is an output
                        | (0 << 2)   /* SCS[2] */
                        | (1 << 3)   /* SCS[3] */
                        | (0 << 8)   /* ENA */
                        | (1 << 9)   /* CLK */
                        | (1 << 10)  /* SIMO */
                        | (1 << 11); /* SOMI */

    2.  it seems also CS[0] is usd for chip selection in the following:

    void SPI_ssel (unsigned long ssel) {
      if (ssel) {
        spiREG2->PCDOUT |=  0x01;    // SCS[0] = high
      } else {
        spiREG2->PCDOUT &= ~0x01;    // SCS[0] = low
      }
    }

    3.  "0x100D0000" is used, so i think CS[1] is used for chip selection in the following: 

    while ((spiREG2->FLG & 0x0200) == 0); // Wait until TXINTFLG is set for previous transmission
      spiREG2->DAT1 = outb | 0x100D0000;

    so it does not work in my project, i have modified SOMI to INPUT, and modified 0x100D0000 to 0x10FE0000, it still does not work.

  • Please see the reply to your other post. Chip select signals are generated automatically. You need to config the required pins as SPI function using the SPIPC0 register.

    Thansk and regards,

    Zhaohong