jiang hao / Mbed 2 deprecated sd

Dependencies:   SDFileSystem mbed

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 #define LEN 2048
00004 SDFileSystem sd(PA_14, PA_13, PA_12, PA_11, "sd"); // the pinout on the mbed Cool Components workshop board  SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd");
00005 //SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd");
00006 Serial uart1(PA_13,PA_14);
00007 FILE *fp;
00008 char buf[LEN];
00009 int main() {
00010     uart1.baud(9600);
00011     uart1.printf("SD Card FAT FileSystem Testing....\r\n");
00012  
00013     mkdir("/sd/mydir", 0777);
00014     
00015     if((fp = fopen("/sd/mydir/sdtest.txt", "w")) == NULL){
00016         error("Could not open file for write\r\n");
00017         return -1;
00018     }
00019     fprintf(fp, "DFRobot Test String ABCDEFG......\r\n");
00020     fclose(fp); 
00021 
00022     if((fp = fopen("/sd/mydir/sdtest.txt", "r")) == NULL){
00023         error("Could not open file for write\r\n");
00024         return -1;
00025     }
00026     memset(buf,0,LEN);
00027     fread(buf,LEN,1,fp);
00028     buf[LEN-1] = 0;
00029     fclose(fp);
00030     uart1.printf("------------read sdtest.txt-----------\r\n");
00031     uart1.printf("%s",buf);
00032     uart1.printf("------------end-----------\r\n");
00033 }