eunkyoung kim / Mbed 2 deprecated SSP_SDcard_Helloworld_WIZwiki-W7500

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by eunkyoung kim

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 #if defined(TARGET_WIZwiki_W7500)
00004 #define MOSI                  PB_3
00005 #define MISO                  PB_2
00006 #define CLK                   PB_1
00007 #define SEL                   PB_0
00008 #endif
00009 
00010 #define MAX_SIZE 100 
00011 SDFileSystem sd(MOSI, MISO, CLK, SEL, "sd"); // the pinout on the mbed Cool Components workshop board
00012 
00013 
00014 int main() {
00015 
00016         char str[MAX_SIZE];
00017         mkdir("/sd/mydir", 0777);
00018         //"w" : {Write) - Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
00019         //"a+" :(append/update) -  open (or create if the file does not exist) for update at the end of the file
00020         FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); 
00021         if(fp == NULL) {
00022             error("Could not open file for write\n");
00023         }
00024         //fprintf(fp, "Hello fun SD Card World!");
00025         printf("Insert data:");
00026         scanf("%s",str);
00027         printf("\r\n");
00028         fflush(stdin);
00029         fprintf(fp,"%s", str);
00030         fclose(fp); 
00031         
00032         printf("Reading from SD card...\r\n");
00033         fp = fopen("/sd/mydir/sdtest.txt", "r");
00034         if (fp != NULL) {
00035              fgets(str,MAX_SIZE,fp);
00036              printf("%s", str);
00037              printf("\r\n");
00038             fclose(fp);
00039         } else {
00040             printf("failed!\n");
00041         }
00042         
00043 }