Read/Write the SD card(using SSP)

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by eunkyoung kim

main.cpp

Committer:
eunkyoungkim
Date:
2015-06-29
Revision:
3:017b99069995
Parent:
2:343b407cf6aa
Child:
4:68cb56ba60c6

File content as of revision 3:017b99069995:

#include "mbed.h"
#include "SDFileSystem.h"
#if defined(TARGET_WIZwiki_W7500)
#define MOSI                  PB_3
#define MISO                  PB_2
#define CLK                   PB_1
#define SEL                   PB_0
#endif

#define MAX_SIZE 100 
SDFileSystem sd(MOSI, MISO, CLK, SEL, "sd"); // the pinout on the mbed Cool Components workshop board

char sdread[MAX_SIZE];
int main() {
    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("%s", sdread);
        fclose(fp);
    } else {
        printf("failed!\n");
    }
}