testing out sd card on sensor pod
Dependencies: SDFileSystem mbed
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 00004 SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS 00005 DigitalIn sd_cs(PTA16); 00006 Serial pc(USBTX, USBRX); 00007 FILE *fp; 00008 00009 uint32_t do_list(const char *fsrc) 00010 { 00011 DIR *d = opendir(fsrc); 00012 struct dirent *p; 00013 uint32_t counter = 0; 00014 00015 while ((p = readdir(d)) != NULL) { 00016 counter++; 00017 printf("%s\n", p->d_name); 00018 } 00019 closedir(d); 00020 return counter; 00021 } 00022 00023 int main() 00024 { 00025 pc.printf("Initializing \n\r"); 00026 wait(1); 00027 pc.printf("Opening nyah/nyoho.txt\n\r"); 00028 00029 wait(1); 00030 fp = fopen("/sd/nyah/nyoho.txt", "r+"); 00031 00032 if (fp == NULL) { 00033 pc.printf("Unable to open the file \r\n"); 00034 } else { 00035 pc.printf("\n\rFile pointer address: 0x%X\n\r", &fp); 00036 00037 pc.printf("\n\rWriting to nyah/nyoho.txt\n\r"); 00038 wait(0.25); 00039 00040 fprintf(fp, "The quick brown fox jumps over the lazy dog"); 00041 00042 rewind(fp); 00043 fprintf(fp, "Seiya is trying to eat the SD card please stop him"); 00044 wait(0.25); 00045 00046 pc.printf("\n\rFlushing the buffer...\n\r"); 00047 int flush = fflush(fp); 00048 wait(0.25); 00049 if (flush == 0) pc.printf("Flush Successful!\n\r"); 00050 else pc.printf("**WARNING** Flush Failed\n\r"); 00051 } 00052 wait(1); 00053 fclose(fp); 00054 pc.printf("\n\rDone\r\n"); 00055 wait(1); 00056 exit(3); 00057 }
Generated on Mon Aug 15 2022 23:19:18 by 1.7.2