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 00004 00005 //SDFileSystem sd(mosi, miso, sclk, cs, "sd"); 00006 00007 SDFileSystem sd(D11, D12, D13, D10, "sd"); // the pinout on the mbed Cool Components workshop board 00008 00009 /* on the Break out Module 00010 G = GND goes to GND 0V 00011 DO = Digital Out goes to MISO D12 00012 CLK = Clock goes to SCLK D13 00013 DI = Digital In goes to MOSI D11 00014 CS = Chip Select goes to CS D10 00015 + = +ve supply goes to 3V3 Check! Slider switch on SD side is set to 3V3 00016 */ 00017 // FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");//Open device "sd" with a folder "mdir" of root on the SD card 00018 00019 00020 char myStr[128]; 00021 00022 int main() { 00023 printf("Start to write!\n"); 00024 00025 mkdir("/sd/mydir", 0777); 00026 00027 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); 00028 if(fp == NULL) { 00029 error("Could not open file for write\n"); 00030 } 00031 fprintf(fp, "Hello World!"); 00032 fprintf(fp, "This is a second line"); 00033 fprintf(fp, "and now a third line"); 00034 fclose(fp); 00035 00036 printf("Finished writing and closed file\n"); 00037 00038 FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); 00039 //fscanf(fp1, "%s", myStr); 00040 fgets(myStr, 12, fp1); 00041 printf("\t%s\n\r",myStr); 00042 fclose(fp1); 00043 }
Generated on Thu Jul 14 2022 13:52:28 by
1.7.2
