Read/Write the SD card(using SSP)
Dependencies: SDFileSystem mbed
Fork of SSP_SDcard_Helloworld_WIZwiki-W7500 by
main.cpp@3:017b99069995, 2015-06-29 (annotated)
- Committer:
- eunkyoungkim
- Date:
- Mon Jun 29 03:38:40 2015 +0000
- Revision:
- 3:017b99069995
- Parent:
- 2:343b407cf6aa
- Child:
- 4:68cb56ba60c6
add TARGER define
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" |
eunkyoungkim | 3:017b99069995 | 3 | #if defined(TARGET_WIZwiki_W7500) |
eunkyoungkim | 3:017b99069995 | 4 | #define MOSI PB_3 |
eunkyoungkim | 3:017b99069995 | 5 | #define MISO PB_2 |
eunkyoungkim | 3:017b99069995 | 6 | #define CLK PB_1 |
eunkyoungkim | 3:017b99069995 | 7 | #define SEL PB_0 |
eunkyoungkim | 3:017b99069995 | 8 | #endif |
eunkyoungkim | 1:f4d825b196e7 | 9 | |
eunkyoungkim | 1:f4d825b196e7 | 10 | #define MAX_SIZE 100 |
eunkyoungkim | 3:017b99069995 | 11 | SDFileSystem sd(MOSI, MISO, CLK, SEL, "sd"); // the pinout on the mbed Cool Components workshop board |
eunkyoungkim | 1:f4d825b196e7 | 12 | |
eunkyoungkim | 1:f4d825b196e7 | 13 | char sdread[MAX_SIZE]; |
mbed_official | 0:bdbd3d6fc5d5 | 14 | int main() { |
mbed_official | 0:bdbd3d6fc5d5 | 15 | mkdir("/sd/mydir", 0777); |
mbed_official | 0:bdbd3d6fc5d5 | 16 | |
mbed_official | 0:bdbd3d6fc5d5 | 17 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 18 | if(fp == NULL) { |
mbed_official | 0:bdbd3d6fc5d5 | 19 | error("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 20 | } |
mbed_official | 0:bdbd3d6fc5d5 | 21 | fprintf(fp, "Hello fun SD Card World!"); |
mbed_official | 0:bdbd3d6fc5d5 | 22 | fclose(fp); |
eunkyoungkim | 1:f4d825b196e7 | 23 | |
eunkyoungkim | 1:f4d825b196e7 | 24 | printf("Reading from SD card...\r\n"); |
eunkyoungkim | 1:f4d825b196e7 | 25 | fp = fopen("/sd/mydir/sdtest.txt", "r"); |
eunkyoungkim | 1:f4d825b196e7 | 26 | if (fp != NULL) { |
eunkyoungkim | 1:f4d825b196e7 | 27 | fgets(sdread,MAX_SIZE,fp); |
eunkyoungkim | 2:343b407cf6aa | 28 | printf("%s", sdread); |
eunkyoungkim | 1:f4d825b196e7 | 29 | fclose(fp); |
eunkyoungkim | 1:f4d825b196e7 | 30 | } else { |
eunkyoungkim | 1:f4d825b196e7 | 31 | printf("failed!\n"); |
eunkyoungkim | 1:f4d825b196e7 | 32 | } |
mbed_official | 0:bdbd3d6fc5d5 | 33 | } |