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.
9 years, 7 months ago.
write works, read fails
I am able to write the file using the example. But when I try to setup the file for read operation, it fails. I'm using an LPC11U24 target. If my flags on line 15 are "w", it works. Any ideas?
#include "mbed.h" #include "SDFileSystem.h" SDFileSystem sd(P1_22, P1_21, P1_20, P1_19, "sd"); // the pinout on the FT33 controller Serial pc(P1_13, P1_14); // xbee port int main() { int i; pc.printf("Hello World!\n"); mkdir("/sd/mydir", 0777); FILE *fp = fopen("/sd/mydir/sdtest.txt", "rw"); if(fp == NULL) { pc.printf("Could not open file for read/write\n"); } else { pc.printf("Successfully opened file for read/write\n"); pc.printf("Writing to card...\n"); fprintf(fp, "Hello fun SD Card World!\r\n"); for(i = 0; i < 25; i++) { fprintf(fp, "%d\r\n", i); } } fclose(fp); pc.printf("Goodbye World!\n"); }