File System Example - Writing a text file on FRMD-K64F board using 4GB Kingston SDHC

Dependencies:   SDFileSystem mbed

Fork of FRDM_K64F-SDCard by Rangel Alvarado

Committer:
issaiass
Date:
Wed Sep 17 23:53:07 2014 +0000
Revision:
0:457fb4f2657b
Initial FRDM-K64F Functional Example with SD File System library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
issaiass 0:457fb4f2657b 1 /*
issaiass 0:457fb4f2657b 2 *******************************************************************************
issaiass 0:457fb4f2657b 3 * HTTP://WWW.CERESCONTROLS.COM
issaiass 0:457fb4f2657b 4 * PANAMÁ, REPÚBLICA DE PANAMÁ
issaiass 0:457fb4f2657b 5 *
issaiass 0:457fb4f2657b 6 * File : main.cpp
issaiass 0:457fb4f2657b 7 * Programer(s) : Rangel Alvarado
issaiass 0:457fb4f2657b 8 * Language : C/C++
issaiass 0:457fb4f2657b 9 * Description : Simple SD Card File System Write
issaiass 0:457fb4f2657b 10 *
issaiass 0:457fb4f2657b 11 * Notes : Using standard mbed classes to write information data in
issaiass 0:457fb4f2657b 12 * the SD Card.
issaiass 0:457fb4f2657b 13 * http://cache.freescale.com/files/32bit/doc/user_guide/FRDMK64FUG.pdf
issaiass 0:457fb4f2657b 14 *
issaiass 0:457fb4f2657b 15 *******************************************************************************
issaiass 0:457fb4f2657b 16 */
issaiass 0:457fb4f2657b 17
issaiass 0:457fb4f2657b 18 #include "mbed.h" // mbed application libraries
issaiass 0:457fb4f2657b 19 #include "SDFileSystem.h" // SD File System functions
issaiass 0:457fb4f2657b 20
issaiass 0:457fb4f2657b 21 #define DAT0 PTE3 // MOSI
issaiass 0:457fb4f2657b 22 #define CMD PTE1 // MISO
issaiass 0:457fb4f2657b 23 #define CLK PTE2 // SCLK
issaiass 0:457fb4f2657b 24 #define CD PTE4 // CS
issaiass 0:457fb4f2657b 25
issaiass 0:457fb4f2657b 26 SDFileSystem sd(DAT0, CMD, CLK, CD, "sd"); // MOSI, MISO, SCLK, CS
issaiass 0:457fb4f2657b 27 Serial pc(USBTX, USBRX); // Virtual COM Port
issaiass 0:457fb4f2657b 28
issaiass 0:457fb4f2657b 29 int main() {
issaiass 0:457fb4f2657b 30 FILE *File = fopen("/sd/sdfile.txt", "w"); // open file
issaiass 0:457fb4f2657b 31 if(File == NULL) { // check if present
issaiass 0:457fb4f2657b 32 pc.printf("No SD Card or bad format\n"); // print message
issaiass 0:457fb4f2657b 33 } else { // otherwise
issaiass 0:457fb4f2657b 34 pc.printf("Ready to write\n"); // message preparing to write
issaiass 0:457fb4f2657b 35 }
issaiass 0:457fb4f2657b 36 fprintf(File, "FRDM-K64F"); // write data
issaiass 0:457fb4f2657b 37 fclose(File); // close file on SD
issaiass 0:457fb4f2657b 38 }