Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
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 }
Generated on Thu Jul 14 2022 14:39:33 by
1.7.2
