TaChing Yu / Mbed 2 deprecated SDCard_Read

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 
00004 Serial pc(USBTX, USBRX);
00005 SDFileSystem sd(PC_3, PC_2, PB_10, PE_2, "sd"); // MOSI, MISO, SCK, CS
00006 
00007 FILE *fp;
00008 char data[100];
00009 
00010 int main() {
00011     wait(1);
00012     pc.printf("Initializing\r\n");
00013     
00014     fp = fopen("/sd/hello.txt", "r");    //檔名改成跟Write時候一樣的名稱
00015     
00016     if (fp == NULL) {
00017         pc.printf("Fail\r\n");
00018     }
00019     
00020     fread( data, sizeof(data), 1, fp );
00021     fclose(fp);
00022     pc.printf("File successfully read!\r\n");
00023     pc.printf(" Your data:\n%s\n",data);
00024 }