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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // example writing to SD card, sford
00002 
00003 #include "mbed.h"
00004 #include "SDFileSystem.h"
00005 
00006 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
00007 
00008 int main() {
00009     printf("Hello World!\n");   
00010 
00011     mkdir("/sd/mydir", 0777);
00012     
00013     FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
00014     if(fp == NULL) {
00015         error("Could not open file for write\n");
00016     }
00017     fprintf(fp, "Hello fun SD Card World!");
00018     fclose(fp); 
00019 
00020     printf("Goodbye World!\n");
00021 }