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.

Using SD card with EK-TMC123GXL

Hello All,

  I am trying to use the fatfs third party library with my launchpad. My code compiles without errors but I cannot seem to write anything to the sd card (which is unlocked). My pin connections are as follow:

PORT A PIN 2 -- SD CARD SCK

PORT A PIN 3 -- SD CARD CS

PORT A PIN 4 -- SD CARD MISO

PORT A PIN 5 -- SD CARD MOSI

 ( I am using this adapter: http://www.lctech-inc.com/Hardware/Detail.aspx?id=0c3b6f7a-d101-4a60-8b56-3abfb7fd818d )

Here is my main code:

int main(void)
{

	/* 
	 * ...More code here...
	*/

	//SDCardInit();
	power_on();

	BOOL a=wait_ready();

	DSTATUS errd; 

	if (a) {
		send_initial_clock_train();
		errd = disk_initialize(0);
		UARTprintf("\nInitialising disk 0. Status = %i\n",errd);
	}

	unsigned int val=65;
	char filename[40];
	while(val < 68)
	{
		// Led on
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

		// Create a new file and write to sd card
		usprintf(filename,"File%i.txt\n",val);
		UARTprintf(filename);
		f_open(&Fil, filename, FA_WRITE | FA_CREATE_NEW);
		SysCtlDelay(SysCtlClockGet()/3);
		f_close(&Fil);
		
		// Led off 
		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

		// Small 1 second delay
		SysCtlDelay(SysCtlClockGet()/3);

		val++;
	}

	power_off();
}

I have include the third_party/fatfs/port/mmc-dk-tm4c123g.c file.

The code compiles without errors, but I can not see any files created on the sd card.

What am I doing wrong?

I would appreciate any help.

Thanks,

Mike

  • Hi Mike,

    Is there a reason why the SDCardInit() function call is commented out?

    Have you looked specifically at the sd_card example for the DK-TM4C123G? It is in the examples/boards/dk-tm4c123g/sd_card folder of the TivaWare directory. You may need to install the complete TivaWare package if you only have the board examples for the LaunchPad.

    The sd_card example uses fatfs and should only differ by the SSI pins used.

    -David

  • Thanks David.

    That example helped a lot. Successfully got my SD card interfaced with the Launchpad.

    In case someone else is reading this is what I have in the working code:

    FRESULT iFResult;
    iFResult = f_mount(0, &g_sFatFs);
    
    if(iFResult != FR_OK) { UARTprintf("f_mount error: %i\n", iFResult); return(1); } 
    else { UARTprintf("\nMounted SD card\n");}
    
    iFResult = f_open(&g_sFileObject,"data.txt", FA_CREATE_ALWAYS|FA_WRITE);
    if(iFResult != FR_OK) { UARTprintf("Error creating file data.txt: %i\n", iFResult); return(1); } 
    else { UARTprintf("\nCreated file data.txt\n");}
    
    
    int a=0;
    unsigned int b; 
    static char buffer[100] = "";
    while (a<10){
    	usprintf(buffer,"step =%i\n",a++);
    	iFResult = f_write(&g_sFileObject,buffer,strlen(buffer),&b);
    	if(iFResult != FR_OK) { UARTprintf("Error writing to data.txt: %i\n", iFResult); return(1); } 
    	else { UARTprintf("Wrote %i words to data.txt: %i\n", b); }
    }
    
    f_close(&g_sFileObject);
    
    
    // Unregister a work area before discard it
    f_mount(0, NULL);