NM500 TEST PGM

Dependencies:   NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed

Committer:
IOP
Date:
Wed Feb 03 07:34:43 2016 +0000
Revision:
7:daaefdca1f78
Parent:
4:68cb56ba60c6
Child:
8:c41405662e53
update mbed lib

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"
IOP 7:daaefdca1f78 3
eunkyoungkim 3:017b99069995 4 #if defined(TARGET_WIZwiki_W7500)
eunkyoungkim 3:017b99069995 5 #define MOSI PB_3
eunkyoungkim 3:017b99069995 6 #define MISO PB_2
eunkyoungkim 3:017b99069995 7 #define CLK PB_1
eunkyoungkim 3:017b99069995 8 #define SEL PB_0
eunkyoungkim 3:017b99069995 9 #endif
eunkyoungkim 1:f4d825b196e7 10
IOP 7:daaefdca1f78 11 #define MAX_SIZE 100
IOP 7:daaefdca1f78 12
eunkyoungkim 3:017b99069995 13 SDFileSystem sd(MOSI, MISO, CLK, SEL, "sd"); // the pinout on the mbed Cool Components workshop board
eunkyoungkim 1:f4d825b196e7 14
eunkyoungkim 4:68cb56ba60c6 15
mbed_official 0:bdbd3d6fc5d5 16 int main() {
eunkyoungkim 4:68cb56ba60c6 17
eunkyoungkim 4:68cb56ba60c6 18 char str[MAX_SIZE];
IOP 7:daaefdca1f78 19
eunkyoungkim 4:68cb56ba60c6 20 mkdir("/sd/mydir", 0777);
eunkyoungkim 4:68cb56ba60c6 21 //"w" : {Write) - Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
eunkyoungkim 4:68cb56ba60c6 22 //"a+" :(append/update) - open (or create if the file does not exist) for update at the end of the file
IOP 7:daaefdca1f78 23
eunkyoungkim 4:68cb56ba60c6 24 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
IOP 7:daaefdca1f78 25
IOP 7:daaefdca1f78 26 if(fp == NULL)
IOP 7:daaefdca1f78 27 {
eunkyoungkim 4:68cb56ba60c6 28 error("Could not open file for write\n");
eunkyoungkim 4:68cb56ba60c6 29 }
IOP 7:daaefdca1f78 30
eunkyoungkim 4:68cb56ba60c6 31 //fprintf(fp, "Hello fun SD Card World!");
eunkyoungkim 4:68cb56ba60c6 32 printf("Insert data:");
eunkyoungkim 4:68cb56ba60c6 33 scanf("%s",str);
eunkyoungkim 4:68cb56ba60c6 34 printf("\r\n");
IOP 7:daaefdca1f78 35
eunkyoungkim 4:68cb56ba60c6 36 fflush(stdin);
eunkyoungkim 4:68cb56ba60c6 37 fprintf(fp,"%s", str);
eunkyoungkim 4:68cb56ba60c6 38 fclose(fp);
eunkyoungkim 4:68cb56ba60c6 39
eunkyoungkim 4:68cb56ba60c6 40 printf("Reading from SD card...\r\n");
IOP 7:daaefdca1f78 41
eunkyoungkim 4:68cb56ba60c6 42 fp = fopen("/sd/mydir/sdtest.txt", "r");
IOP 7:daaefdca1f78 43
IOP 7:daaefdca1f78 44 if (fp != NULL)
IOP 7:daaefdca1f78 45 {
eunkyoungkim 4:68cb56ba60c6 46 fgets(str,MAX_SIZE,fp);
eunkyoungkim 4:68cb56ba60c6 47 printf("%s", str);
eunkyoungkim 4:68cb56ba60c6 48 printf("\r\n");
eunkyoungkim 4:68cb56ba60c6 49 fclose(fp);
IOP 7:daaefdca1f78 50 }
IOP 7:daaefdca1f78 51 else
IOP 7:daaefdca1f78 52 {
eunkyoungkim 4:68cb56ba60c6 53 printf("failed!\n");
eunkyoungkim 4:68cb56ba60c6 54 }
eunkyoungkim 4:68cb56ba60c6 55
mbed_official 0:bdbd3d6fc5d5 56 }