Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 8 months ago.
Cannot open file for read in microSD card with KL25Z
Hi, I tried to read a file from a micro SD card with KL25Z, then I cannot open file for read. But I was able to write a file. Why?? I don't know how to do?
Thanks.
1 Answer
11 years, 8 months ago.
Hi, my code is here. Writing(below) is possible, but reading(above) is impossible. ??
SD card module is sparkfun micro SD shield. I don't use "/sd/mydir" folder.
#include "mbed.h" #include "SDFileSystem.h" SDFileSystem sd(PTD2, PTD3, PTD1, PTA4, "sd"); // the pinout on the mbed Cool Components workshop board char buffer[64]={"abc"}; DigitalOut grn(PTB19); DigitalOut red(PTB18); DigitalOut blu(PTD1); int main() { grn = 1; red = 1; blu = 1; printf("Hello World!\n"); //mkdir("/sd/mydir", 0777); blu = 0; FILE *fp = fopen("/sd/sdtest.txt", "r"); grn = 0; blu = 1; if(fp == NULL) { error("\r\nCould not open file for read\n"); } //fprintf(fp, "Hello fun SD Card World!"); grn = 1; red = 0; fgets(buffer, 64, fp); red = 1; blu = 0; fclose(fp); printf("\r\n%s", buffer); printf("Goodbye World!"); while(1) { } } /*#include "mbed.h" #include "SDFileSystem.h" SDFileSystem sd(PTD2, PTD3, PTD1, PTA4, "sd"); // the pinout on the mbed Cool Components workshop board int main() { printf("Hello World!\n"); //mkdir("/sd/mydir", 0777); FILE *fp = fopen("/sd/sdtest.txt", "w"); if(fp == NULL) { error("Could not open file for write\n"); } fprintf(fp, "Hello fun SD Card World!"); fclose(fp); printf("Goodbye World!\n"); }*/
Hi, can you publish your code please?
posted by Samuel Mokrani 05 Mar 2013