An example using the SDFileSystem library to create a directory and write a fiel to an SD card, using its SPI interface

Dependencies:   mbed SDFileSystem

Committer:
simon
Date:
Mon Sep 06 10:01:55 2010 +0000
Revision:
1:27aaaa9f462b
Parent:
0:aee5cf626b88
Update example to include mkdir(), and use the pinout of the cool components workshop board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 1:27aaaa9f462b 1 // example writing to SD card, sford
simon 1:27aaaa9f462b 2
simon 0:aee5cf626b88 3 #include "mbed.h"
simon 0:aee5cf626b88 4 #include "SDFileSystem.h"
simon 0:aee5cf626b88 5
simon 1:27aaaa9f462b 6 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
simon 0:aee5cf626b88 7
simon 0:aee5cf626b88 8 int main() {
simon 0:aee5cf626b88 9 printf("Hello World!\n");
simon 0:aee5cf626b88 10
simon 1:27aaaa9f462b 11 mkdir("/sd/mydir", 0777);
simon 1:27aaaa9f462b 12
simon 1:27aaaa9f462b 13 FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
simon 0:aee5cf626b88 14 if(fp == NULL) {
simon 0:aee5cf626b88 15 error("Could not open file for write\n");
simon 0:aee5cf626b88 16 }
simon 0:aee5cf626b88 17 fprintf(fp, "Hello fun SD Card World!");
simon 0:aee5cf626b88 18 fclose(fp);
simon 0:aee5cf626b88 19
simon 0:aee5cf626b88 20 printf("Goodbye World!\n");
simon 0:aee5cf626b88 21 }