9 years, 6 months ago.

Problem when Using SDFileSystem

Hi there,

I use your latest library + mbed SDFileSystem with LCD similar to Display 3 (Banggood). I connect SD card and LCD with same SPI lines but different CS pin.

I made simple program to read file from SD card then display the result on LCD, it worked OK. However, when I access SD card for more than once (either read or write), the program hangs after the first SD card access.

At first, I thought it was caused by SDFileSystem. But, I found out that if I remove the LCD part from program, it runs normal again. (in this case, I use serial port to print the result of SD card writing or reading).

Below are the snippet of my program:

    FILE *fp;
    signed char c;
    int i=0;
    char s[255];
    char rcv[255]; 
    
    //construct file location
    sprintf(s,"/sd/cmd1.txt");
    
    //read from file
    fp = fopen(s,"r");
    if(fp != NULL) {
        while(1) {
            c = fgetc(fp);
            if(c == EOF){
                break;
            }
            rcv[i] = c;
            i++;
        }    
    }
    fclose(fp);
    DBG.printf(rcv);     //print to serial port
    TFT.printf(rcv);     //print to TFT LCD
    wait(10);

    //This is where program hangs if TFT.printf is included
    
    //construct file location
    sprintf(s,"/sd/cmd2.txt");
    
    //write to file
    fp = fopen(s,"w");
    if(fp != NULL) {
        fprintf(fp,"test");
        fclose(fp);  
    }
    fclose(fp);
    DBG.printf("file written \r\n");
    TFT.printf("file written \r\n");

Update 1: I've tried to use different SPI lines for LCD and SD Card, and it works. However, when I use same SPI lines, it doesn't work. From my understanding, SPI lines can be used for multiple devices with one CS pin (active low) for each devices. I've tried to deactivate/activate LCD before/after accessing SD card and vice versa, but it still doesn't work.

Update 2: I found the solution. To use LCD and SD Card with same SPI line, you need to disable SPI DMA. However, it makes LCD slower in displaying things.

Thanks for your cooperation.

Related article: https://developer.mbed.org/questions/724/SDcard-TFT-display/

TC

Question relating to:

Lib for the new LCD Display with ILI9341 controller

Quick sanity check... s is defined as a char array at least 13 long? cmd1.txt is less than 255 bytes long?

posted by Andy A 15 May 2015

Thanks for your comment Andy. I've updated the question with s initialization. Yes, the cmd1.txt file is less than 255 bytes.

posted by Tigor Christian 15 May 2015
Be the first to answer this question.