sd read/write

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

main.cpp

Committer:
eunkyoungkim
Date:
2015-06-29
Revision:
1:f4d825b196e7
Parent:
0:bdbd3d6fc5d5
Child:
2:343b407cf6aa

File content as of revision 1:f4d825b196e7:

#include "mbed.h"
#include "SDFileSystem.h"

#define MAX_SIZE 100 
SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // the pinout on the mbed Cool Components workshop board

char sdread[MAX_SIZE];
int main() {
    printf("Hello World!\n");   
 
    mkdir("/sd/mydir", 0777);
    
    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
    if(fp == NULL) {
        error("Could not open file for write\n");
    }
    fprintf(fp, "Hello fun SD Card World!");
    fclose(fp); 
    
    printf("Reading from SD card...\r\n");
    fp = fopen("/sd/mydir/sdtest.txt", "r");
    if (fp != NULL) {
         fgets(sdread,MAX_SIZE,fp);
         printf("READ_STR = %s", sdread);
        fclose(fp);
    } else {
        printf("failed!\n");
    }
}