8 years, 10 months ago.

ST Nucleo L152RE and SD Card Shiled by SEEED Studio

hi, i use this SD Card Shield SEEED Studio version 4.1 11/11/2013 i use the example present on mbed site

#include "mbed.h"
#include "SDFileSystem.h"
Serial pc(USBTX, USBRX);
SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS
FILE *fp;
 
int main() {
    wait(2);
    pc.printf("Initializing\r\n");
    
    fp = fopen("/sd/hello.txt", "r");
    if (fp != NULL) {
        fclose(fp);
        remove("/sd/hello.txt");
        pc.printf("Remove an existing file with the same name\r\n");
    }
    
    fp = fopen("/sd/hello.txt", "w");
    if (fp == NULL) { 
        pc.printf("Unable to write the file\r\n");
    } else {
        fprintf(fp, "mbed SDCard application!");
        fclose(fp);
        pc.printf("File successfully written!\r\n");
    }
}

If i use only this code i have this message: Initializing Unable to write the file if i use this configuration with wire (i see a post user's mbed)

/media/uploads/antoniolinux/immagine2.png /media/uploads/antoniolinux/immagine.png

when i run the code i have this message: Initializing Unable to write the file

i 'don't know where is the problem can you help me?

best reards A.

Hi Antonio You are missing a "fclose(fp)" between the read and write routines good to 'close' each file 'open' for all conditions or use Different File Pointers i.e fp1 fp2 fpn etc., Regards

Martin

posted by Martin Simpson 23 Jun 2015

1 Answer

8 years, 10 months ago.

In wiki on seeedstudio.com, for version 4.0 this shield is determined that SD_CS is on D4. On your code above in line 4 this signal is on D10. Change this parameter and test again.

update: I tested your (here above) program with Nucleo L152 and worked well (a file created and the message "... succesfull .." there was one). I changed only pin definitions in line 4, to meet the needs of my shield (similar to that of seeedstudio).

Accepted Answer

thx, now all work well. best regards. A.

posted by Antoniolinux B. 01 Jul 2015