Patrick McNamara / Mbed 2 deprecated ADC_SDcard_serial

Dependencies:   BufferedSerial SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sd_card.h Source File

sd_card.h

00001 #include "mbed.h"
00002 
00003 
00004 
00005 /************************************************************************
00006 * handles creating an sd card object, opening the .txt file
00007 * then writes array c and closes file
00008 ************************************************************************/
00009 void writeToSdCard()
00010 {
00011     pc.printf("Begin write SD Card routine\r\n");
00012     mkdir("/sd/mydir", 0777);
00013 
00014     FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
00015     
00016     while(fp == NULL) 
00017     {
00018         error("Could not open file for write\r\n");
00019     }
00020 
00021     pc.printf("Start writing...");
00022     
00023     for (int i = 0; i < arrayCount; i++)
00024     {    
00025         fprintf(fp, "%f\r\n", squibCLT_array[i]);  
00026     }
00027 
00028     fclose(fp);         
00029     pc.printf("Done\r\n");
00030 }
00031 
00032 
00033 
00034 /************************************************************************
00035 * handles opening the named .txt file and stores everything 
00036 * to the char array c and then closes the file.
00037 * 
00038 * 
00039 ************************************************************************/
00040 void readFromSdCard()
00041 {
00042     pc.printf("Begin read SD Card routine\r\n");
00043     
00044     FILE *fp = fopen("/sd/mydir/sdtest.txt", "r");
00045     
00046     while(fp == NULL) 
00047     {
00048         error("Could not open file for read\r\n");
00049     }
00050     
00051     pc.printf("Starting read...");
00052     
00053     for (int i = 0; i < arrayCount; i++)
00054     {
00055         fscanf(fp, "%f", &squibCLT_array2[i]);
00056     }           
00057 
00058     fclose(fp);
00059 
00060 
00061 #if defined(__MICROLIB) && defined(__ARMCC_VERSION)                         // with microlib and ARM compiler  //possible sd card library bug.  Not sure if this helps
00062     free(fp);
00063 #endif
00064 
00065     pc.printf("Done.\r\n");
00066 
00067 }
00068