Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed
main.cpp
- Committer:
- ImageWriter
- Date:
- 2015-04-17
- Revision:
- 0:96613601cfb9
File content as of revision 0:96613601cfb9:
#include "mbed.h"
#include "SDFileSystem.h"
//Create an SDFileSystem object
//SDFileSystem sd(PA_7, PA_6, PA_5, PA_15, "sd");// MOSI, MISO, SCK, CS
SDFileSystem sd(D11, D12, D13, D10, "sd");// MOSI, MISO, SCK, CS
Serial pc(USBTX, USBRX);
int main() {
// pc.baud(19200);
pc.baud(9600);
for(int i=5; i>0; i--)
{
pc.printf("Wait %i seconds..\r\n",i);
wait(1);
}
pc.printf("Initializing\r\n");
//Mount the filesystem
// sd.mount();
//Perform a write test
pc.printf("\nWriting to SD card...");
FILE *fp = fopen("/sd/sdtest.txt", "a+");
wait(2);
if (fp != NULL) {
fprintf(fp, "We're writing to an SD card!");
fclose(fp);
pc.printf("success!\n");
} else {
pc.printf("failed!\n");
}
//Perform a read test
pc.printf("Reading from SD card...");
fp = fopen("/sd/sdtest.txt", "r");
if (fp != NULL) {
char c = fgetc(fp);
if (c == 'W')
pc.printf("success!\n");
else
pc.printf("incorrect char (%c)!\n", c);
fclose(fp);
} else {
pc.printf("failed!\n");
}
//Unmount the filesystem
// sd.unmount();
}