sd read/write

Dependencies:   SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Committer:
eunkyoungkim
Date:
Mon Jun 29 02:18:54 2015 +0000
Revision:
2:343b407cf6aa
Parent:
1:f4d825b196e7
modify main .c;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
mbed_official 0:bdbd3d6fc5d5 2 #include "SDFileSystem.h"
eunkyoungkim 1:f4d825b196e7 3
eunkyoungkim 1:f4d825b196e7 4 #define MAX_SIZE 100
eunkyoungkim 1:f4d825b196e7 5 SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // the pinout on the mbed Cool Components workshop board
eunkyoungkim 1:f4d825b196e7 6
eunkyoungkim 1:f4d825b196e7 7 char sdread[MAX_SIZE];
mbed_official 0:bdbd3d6fc5d5 8 int main() {
mbed_official 0:bdbd3d6fc5d5 9 mkdir("/sd/mydir", 0777);
mbed_official 0:bdbd3d6fc5d5 10
mbed_official 0:bdbd3d6fc5d5 11 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
mbed_official 0:bdbd3d6fc5d5 12 if(fp == NULL) {
mbed_official 0:bdbd3d6fc5d5 13 error("Could not open file for write\n");
mbed_official 0:bdbd3d6fc5d5 14 }
mbed_official 0:bdbd3d6fc5d5 15 fprintf(fp, "Hello fun SD Card World!");
mbed_official 0:bdbd3d6fc5d5 16 fclose(fp);
eunkyoungkim 1:f4d825b196e7 17
eunkyoungkim 1:f4d825b196e7 18 printf("Reading from SD card...\r\n");
eunkyoungkim 1:f4d825b196e7 19 fp = fopen("/sd/mydir/sdtest.txt", "r");
eunkyoungkim 1:f4d825b196e7 20 if (fp != NULL) {
eunkyoungkim 1:f4d825b196e7 21 fgets(sdread,MAX_SIZE,fp);
eunkyoungkim 2:343b407cf6aa 22 printf("%s", sdread);
eunkyoungkim 1:f4d825b196e7 23 fclose(fp);
eunkyoungkim 1:f4d825b196e7 24 } else {
eunkyoungkim 1:f4d825b196e7 25 printf("failed!\n");
eunkyoungkim 1:f4d825b196e7 26 }
mbed_official 0:bdbd3d6fc5d5 27 }