by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   FATFileSystem2 SDFileSystem mbed

Committer:
robt
Date:
Fri May 24 22:16:51 2013 +0000
Revision:
0:7f3dfc9ab361
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:7f3dfc9ab361 1 /* Program Example 10.4: writing data to an SD card
robt 0:7f3dfc9ab361 2 */
robt 0:7f3dfc9ab361 3
robt 0:7f3dfc9ab361 4 #include "mbed.h"
robt 0:7f3dfc9ab361 5 #include "SDFileSystem.h"
robt 0:7f3dfc9ab361 6
robt 0:7f3dfc9ab361 7 SDFileSystem sd(p11, p12, p13, p14, "sd"); // MOSI, MISO, SCLK, CS
robt 0:7f3dfc9ab361 8 Serial pc(USBTX, USBRX);
robt 0:7f3dfc9ab361 9
robt 0:7f3dfc9ab361 10 int main() {
robt 0:7f3dfc9ab361 11
robt 0:7f3dfc9ab361 12 FILE *File = fopen("/sd/sdfile.txt", "w"); // open file
robt 0:7f3dfc9ab361 13 if(File == NULL) { // check for file pointer
robt 0:7f3dfc9ab361 14 pc.printf("Could not open file for write\n");
robt 0:7f3dfc9ab361 15 }else{
robt 0:7f3dfc9ab361 16 pc.printf("SD card file succesfully opened\n");
robt 0:7f3dfc9ab361 17 }
robt 0:7f3dfc9ab361 18 fprintf(File, "Here's some sample text on the SD card"); // write data
robt 0:7f3dfc9ab361 19 fclose(File); // close file
robt 0:7f3dfc9ab361 20
robt 0:7f3dfc9ab361 21 }