NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Committer:
eunkyoungkim
Date:
Mon Jun 29 01:38:35 2015 +0000
Revision:
1:f4d825b196e7
Parent:
0:bdbd3d6fc5d5
Child:
2:343b407cf6aa
SD card read/Write; view the terminal window

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 printf("Hello World!\n");
mbed_official 0:bdbd3d6fc5d5 10
mbed_official 0:bdbd3d6fc5d5 11 mkdir("/sd/mydir", 0777);
mbed_official 0:bdbd3d6fc5d5 12
mbed_official 0:bdbd3d6fc5d5 13 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
mbed_official 0:bdbd3d6fc5d5 14 if(fp == NULL) {
mbed_official 0:bdbd3d6fc5d5 15 error("Could not open file for write\n");
mbed_official 0:bdbd3d6fc5d5 16 }
mbed_official 0:bdbd3d6fc5d5 17 fprintf(fp, "Hello fun SD Card World!");
mbed_official 0:bdbd3d6fc5d5 18 fclose(fp);
eunkyoungkim 1:f4d825b196e7 19
eunkyoungkim 1:f4d825b196e7 20 printf("Reading from SD card...\r\n");
eunkyoungkim 1:f4d825b196e7 21 fp = fopen("/sd/mydir/sdtest.txt", "r");
eunkyoungkim 1:f4d825b196e7 22 if (fp != NULL) {
eunkyoungkim 1:f4d825b196e7 23 fgets(sdread,MAX_SIZE,fp);
eunkyoungkim 1:f4d825b196e7 24 printf("READ_STR = %s", sdread);
eunkyoungkim 1:f4d825b196e7 25 fclose(fp);
eunkyoungkim 1:f4d825b196e7 26 } else {
eunkyoungkim 1:f4d825b196e7 27 printf("failed!\n");
eunkyoungkim 1:f4d825b196e7 28 }
mbed_official 0:bdbd3d6fc5d5 29 }