SD interfacing

Dependencies:   SDFileSystem mbed

Committer:
chetanpatil
Date:
Wed Nov 25 12:02:52 2015 +0000
Revision:
0:3cd4416d0506
sd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chetanpatil 0:3cd4416d0506 1 #include "mbed.h"
chetanpatil 0:3cd4416d0506 2 #include "SDFileSystem.h"
chetanpatil 0:3cd4416d0506 3 Serial pc(USBTX, USBRX);
chetanpatil 0:3cd4416d0506 4 //Create an SDFileSystem object
chetanpatil 0:3cd4416d0506 5 SDFileSystem sd(p5, p6, p7, p8, "sd");
chetanpatil 0:3cd4416d0506 6
chetanpatil 0:3cd4416d0506 7 int main()
chetanpatil 0:3cd4416d0506 8 {
chetanpatil 0:3cd4416d0506 9
chetanpatil 0:3cd4416d0506 10 char buff[255];
chetanpatil 0:3cd4416d0506 11 FILE *fp = fopen("/sd/sdtest.txt", "w");
chetanpatil 0:3cd4416d0506 12
chetanpatil 0:3cd4416d0506 13 if(fp == NULL) {
chetanpatil 0:3cd4416d0506 14
chetanpatil 0:3cd4416d0506 15 error("Could not open file for write\n");
chetanpatil 0:3cd4416d0506 16
chetanpatil 0:3cd4416d0506 17 }
chetanpatil 0:3cd4416d0506 18 else
chetanpatil 0:3cd4416d0506 19 {
chetanpatil 0:3cd4416d0506 20 printf("successful\n");
chetanpatil 0:3cd4416d0506 21
chetanpatil 0:3cd4416d0506 22 fprintf(fp,"Sagar file found", buff );
chetanpatil 0:3cd4416d0506 23 }
chetanpatil 0:3cd4416d0506 24
chetanpatil 0:3cd4416d0506 25
chetanpatil 0:3cd4416d0506 26
chetanpatil 0:3cd4416d0506 27 fclose(fp);
chetanpatil 0:3cd4416d0506 28 FILE *fp1 = fopen("/sd/sdtest.txt", "r");
chetanpatil 0:3cd4416d0506 29
chetanpatil 0:3cd4416d0506 30 if(fp1 == NULL) {
chetanpatil 0:3cd4416d0506 31
chetanpatil 0:3cd4416d0506 32 error("Could not open file for write\n");
chetanpatil 0:3cd4416d0506 33
chetanpatil 0:3cd4416d0506 34 }
chetanpatil 0:3cd4416d0506 35 else if(fp == fp1)
chetanpatil 0:3cd4416d0506 36 {
chetanpatil 0:3cd4416d0506 37 printf("File is same\n");
chetanpatil 0:3cd4416d0506 38 fscanf(fp, "%s", buff);
chetanpatil 0:3cd4416d0506 39 printf("%s",buff);
chetanpatil 0:3cd4416d0506 40 }
chetanpatil 0:3cd4416d0506 41
chetanpatil 0:3cd4416d0506 42
chetanpatil 0:3cd4416d0506 43
chetanpatil 0:3cd4416d0506 44 fclose(fp1);
chetanpatil 0:3cd4416d0506 45
chetanpatil 0:3cd4416d0506 46
chetanpatil 0:3cd4416d0506 47 }