mbed sd

Dependencies:   SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
jh_ndm
Date:
Fri Jul 15 08:03:23 2016 +0000
Parent:
0:27143f32cefd
Commit message:
DFRobot SD

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jul 15 01:21:28 2016 +0000
+++ b/main.cpp	Fri Jul 15 08:03:23 2016 +0000
@@ -1,20 +1,33 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
- 
+#define LEN 2048
 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");
 //SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd");
 Serial uart1(PA_13,PA_14);
+FILE *fp;
+char buf[LEN];
 int main() {
-    uart1.printf("Hello World!\n");   
+    uart1.baud(9600);
+    uart1.printf("SD Card FAT FileSystem Testing....\r\n");
  
     mkdir("/sd/mydir", 0777);
     
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
+    if((fp = fopen("/sd/mydir/sdtest.txt", "w")) == NULL){
+        error("Could not open file for write\r\n");
+        return -1;
     }
-    fprintf(fp, "Hello fun SD1 Card World!");
+    fprintf(fp, "DFRobot Test String ABCDEFG......\r\n");
     fclose(fp); 
- 
-    uart1.printf("Goodbye World!\n");
+
+    if((fp = fopen("/sd/mydir/sdtest.txt", "r")) == NULL){
+        error("Could not open file for write\r\n");
+        return -1;
+    }
+    memset(buf,0,LEN);
+    fread(buf,LEN,1,fp);
+    buf[LEN-1] = 0;
+    fclose(fp);
+    uart1.printf("------------read sdtest.txt-----------\r\n");
+    uart1.printf("%s",buf);
+    uart1.printf("------------end-----------\r\n");
 }