SDFileSystem example for the Wi-Go2 module

Dependencies:   SDFileSystem mbed

Compile this program and upload it to your Wi-Go2 board. On a serial terminal program such as TeraTerm you can follow the progress.

After a succesfull it will have created a Wi-Go folder on your SD card, in it is a text file with some text. You can verify on for example your computer if it is there.

Note:

For some reason my SD-card refuses the first command, which is why the mkdir command is included twice. I believe the issue is my SD-card and not the Wi-Go board. If your SD-card behaves normal this extra command will not give you any problems. In case you also have the same issue there will be some error messages printed on your terminal. As long as it says "Finished" at the end the program completed succesfully.

Committer:
Sissors
Date:
Thu Oct 24 14:38:12 2013 +0000
Revision:
0:0dd7eb91a136
V1.0
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:0dd7eb91a136 1 /*
Sissors 0:0dd7eb91a136 2 Compile this program and upload it to your Wi-Go2 board. On a serial terminal
Sissors 0:0dd7eb91a136 3 program such as TeraTerm you can follow the progress.
Sissors 0:0dd7eb91a136 4
Sissors 0:0dd7eb91a136 5 After a succesfull it will have created a Wi-Go folder on your SD card,
Sissors 0:0dd7eb91a136 6 in it is a text file with some text. You can verify on for example your computer
Sissors 0:0dd7eb91a136 7 if it is there.
Sissors 0:0dd7eb91a136 8
Sissors 0:0dd7eb91a136 9
Sissors 0:0dd7eb91a136 10 Note:
Sissors 0:0dd7eb91a136 11 For some reason my SD-card refuses the first command, which is why the mkdir command
Sissors 0:0dd7eb91a136 12 is included twice. I believe the issue is my SD-card and not the Wi-Go board. If your
Sissors 0:0dd7eb91a136 13 SD-card behaves normal this extra command will not give you any problems. In case
Sissors 0:0dd7eb91a136 14 you also have the same issue there will be some error messages printed on your
Sissors 0:0dd7eb91a136 15 terminal. As long as it says "Finished" at the end the program completed
Sissors 0:0dd7eb91a136 16 succesfully.
Sissors 0:0dd7eb91a136 17 */
Sissors 0:0dd7eb91a136 18
Sissors 0:0dd7eb91a136 19 #include "mbed.h"
Sissors 0:0dd7eb91a136 20 #include "SDFileSystem.h"
Sissors 0:0dd7eb91a136 21
Sissors 0:0dd7eb91a136 22 DigitalOut SD_EN(PTE3); // Enable signal for SD Card
Sissors 0:0dd7eb91a136 23 DigitalIn SD_CardDetect(PTE2); // Card detect signal
Sissors 0:0dd7eb91a136 24 SDFileSystem sd(PTD6, PTD7, PTB11, PTE5, "sd"); // The pinout on the Wi-Go2 module
Sissors 0:0dd7eb91a136 25
Sissors 0:0dd7eb91a136 26 int main() {
Sissors 0:0dd7eb91a136 27 SD_EN = 0;
Sissors 0:0dd7eb91a136 28
Sissors 0:0dd7eb91a136 29 printf("Enter SD Card!\r\n");
Sissors 0:0dd7eb91a136 30
Sissors 0:0dd7eb91a136 31 while(SD_CardDetect != 0); // Wait until card is detected
Sissors 0:0dd7eb91a136 32
Sissors 0:0dd7eb91a136 33 SD_EN = 1; // Enable SD Card, wait a bit to make sure SD card is properly inserted
Sissors 0:0dd7eb91a136 34 wait(1);
Sissors 0:0dd7eb91a136 35
Sissors 0:0dd7eb91a136 36 printf("Card detected!\r\n");
Sissors 0:0dd7eb91a136 37
Sissors 0:0dd7eb91a136 38 mkdir("/sd/Wi-Go", 0777);
Sissors 0:0dd7eb91a136 39 mkdir("/sd/Wi-Go", 0777);
Sissors 0:0dd7eb91a136 40
Sissors 0:0dd7eb91a136 41 FILE *fp = fopen("/sd/Wi-Go/sdtest.txt", "w");
Sissors 0:0dd7eb91a136 42 if(fp == NULL) {
Sissors 0:0dd7eb91a136 43 error("Could not open file for write\n\r");
Sissors 0:0dd7eb91a136 44 }
Sissors 0:0dd7eb91a136 45 fprintf(fp, "Hello Wi-Go SD card!");
Sissors 0:0dd7eb91a136 46 fclose(fp);
Sissors 0:0dd7eb91a136 47
Sissors 0:0dd7eb91a136 48 printf("Finished :-) \r\n");
Sissors 0:0dd7eb91a136 49 }