test
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@4:73d5d4c507c9, 2017-10-19 (annotated)
- Committer:
- martinsimpson
- Date:
- Thu Oct 19 10:13:52 2017 +0000
- Revision:
- 4:73d5d4c507c9
- Parent:
- 2:886ae0153478
First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
mbed_official | 0:bdbd3d6fc5d5 | 3 | |
martinsimpson | 4:73d5d4c507c9 | 4 | |
martinsimpson | 4:73d5d4c507c9 | 5 | //SDFileSystem sd(mosi, miso, sclk, cs, "sd"); |
martinsimpson | 4:73d5d4c507c9 | 6 | |
martinsimpson | 2:886ae0153478 | 7 | SDFileSystem sd(D11, D12, D13, D10, "sd"); // the pinout on the mbed Cool Components workshop board |
martinsimpson | 2:886ae0153478 | 8 | |
martinsimpson | 4:73d5d4c507c9 | 9 | /* on the Break out Module |
martinsimpson | 4:73d5d4c507c9 | 10 | G = GND goes to GND 0V |
martinsimpson | 4:73d5d4c507c9 | 11 | DO = Digital Out goes to MISO D12 |
martinsimpson | 4:73d5d4c507c9 | 12 | CLK = Clock goes to SCLK D13 |
martinsimpson | 4:73d5d4c507c9 | 13 | DI = Digital In goes to MOSI D11 |
martinsimpson | 4:73d5d4c507c9 | 14 | CS = Chip Select goes to CS D10 |
martinsimpson | 4:73d5d4c507c9 | 15 | + = +ve supply goes to 3V3 Check! Slider switch on SD side is set to 3V3 |
martinsimpson | 4:73d5d4c507c9 | 16 | */ |
martinsimpson | 4:73d5d4c507c9 | 17 | // FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");//Open device "sd" with a folder "mdir" of root on the SD card |
martinsimpson | 4:73d5d4c507c9 | 18 | |
martinsimpson | 4:73d5d4c507c9 | 19 | |
martinsimpson | 2:886ae0153478 | 20 | char myStr[128]; |
martinsimpson | 2:886ae0153478 | 21 | |
mbed_official | 0:bdbd3d6fc5d5 | 22 | int main() { |
martinsimpson | 2:886ae0153478 | 23 | printf("Start to write!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 24 | |
mbed_official | 0:bdbd3d6fc5d5 | 25 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 26 | |
mbed_official | 0:bdbd3d6fc5d5 | 27 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 28 | if(fp == NULL) { |
mbed_official | 0:bdbd3d6fc5d5 | 29 | error("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 30 | } |
martinsimpson | 2:886ae0153478 | 31 | fprintf(fp, "Hello World!"); |
martinsimpson | 2:886ae0153478 | 32 | fprintf(fp, "This is a second line"); |
martinsimpson | 2:886ae0153478 | 33 | fprintf(fp, "and now a third line"); |
mbed_official | 0:bdbd3d6fc5d5 | 34 | fclose(fp); |
mbed_official | 0:bdbd3d6fc5d5 | 35 | |
martinsimpson | 2:886ae0153478 | 36 | printf("Finished writing and closed file\n"); |
martinsimpson | 2:886ae0153478 | 37 | |
martinsimpson | 2:886ae0153478 | 38 | FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); |
martinsimpson | 2:886ae0153478 | 39 | //fscanf(fp1, "%s", myStr); |
martinsimpson | 2:886ae0153478 | 40 | fgets(myStr, 12, fp1); |
martinsimpson | 2:886ae0153478 | 41 | printf("\t%s\n\r",myStr); |
martinsimpson | 2:886ae0153478 | 42 | fclose(fp1); |
mbed_official | 0:bdbd3d6fc5d5 | 43 | } |