Reading Analog Ports and Saving in a micro SD CARD with the KL25z

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by Neil Thiessen

Revision:
12:bd8b17cd6a7b
Parent:
11:2be49b81dc0b
Child:
16:d68a6d4050f2
--- a/main.cpp	Fri Aug 15 17:55:35 2014 +0000
+++ b/main.cpp	Mon Aug 18 15:11:09 2014 +0000
@@ -39,16 +39,18 @@
     FileHandle* file = sd.open("Test File.bin", O_RDONLY);
     if (file != NULL) {
         timer.start();
-        while (file->read(buffer, sizeof(buffer)) == sizeof(buffer));
+        int iterations = 0;
+        while (file->read(buffer, sizeof(buffer)) == sizeof(buffer))
+            iterations++;
         timer.stop();
-        if (file->close())
+        if (iterations != (1048576 / sizeof(buffer)))
+            printf("read error!\n");
+        else if (file->close())
             printf("failed to close file!\n");
-        else {
-            if (sd.remove("Test File.bin"))
-                printf("failed to delete file!\n");
-            else
-                printf("done!\n\tResult: %.2fKB/s\n", 1024 / (timer.read_us() / 1000000.0));
-        }
+        else if (sd.remove("Test File.bin"))
+            printf("failed to delete file!\n");
+        else
+            printf("done!\n\tResult: %.2fKB/s\n", 1024 / (timer.read_us() / 1000000.0));
         timer.reset();
     } else {
         printf("failed to open file!\n");
@@ -57,9 +59,10 @@
 
 int main()
 {
-    //Configure CRC and large frames
+    //Configure CRC, large frames, and write validation
     sd.crc(true);
     sd.large_frames(true);
+    sd.write_validation(true);
 
     //Fill the buffer with random data for the write test
     srand(time(NULL));