NM500 TEST PGM
Dependencies: NM500Lib_Socket NM500_Test_Socket SDFileSystem_Socket mbed
main.cpp@4:68cb56ba60c6, 2015-07-02 (annotated)
- Committer:
- eunkyoungkim
- Date:
- Thu Jul 02 07:37:06 2015 +0000
- Revision:
- 4:68cb56ba60c6
- Parent:
- 3:017b99069995
- Child:
- 7:daaefdca1f78
Read the SD(using SSP)
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 | 4:68cb56ba60c6 | 13 | |
mbed_official | 0:bdbd3d6fc5d5 | 14 | int main() { |
eunkyoungkim | 4:68cb56ba60c6 | 15 | |
eunkyoungkim | 4:68cb56ba60c6 | 16 | char str[MAX_SIZE]; |
eunkyoungkim | 4:68cb56ba60c6 | 17 | mkdir("/sd/mydir", 0777); |
eunkyoungkim | 4:68cb56ba60c6 | 18 | //"w" : {Write) - Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. |
eunkyoungkim | 4:68cb56ba60c6 | 19 | //"a+" :(append/update) - open (or create if the file does not exist) for update at the end of the file |
eunkyoungkim | 4:68cb56ba60c6 | 20 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
eunkyoungkim | 4:68cb56ba60c6 | 21 | if(fp == NULL) { |
eunkyoungkim | 4:68cb56ba60c6 | 22 | error("Could not open file for write\n"); |
eunkyoungkim | 4:68cb56ba60c6 | 23 | } |
eunkyoungkim | 4:68cb56ba60c6 | 24 | //fprintf(fp, "Hello fun SD Card World!"); |
eunkyoungkim | 4:68cb56ba60c6 | 25 | printf("Insert data:"); |
eunkyoungkim | 4:68cb56ba60c6 | 26 | scanf("%s",str); |
eunkyoungkim | 4:68cb56ba60c6 | 27 | printf("\r\n"); |
eunkyoungkim | 4:68cb56ba60c6 | 28 | fflush(stdin); |
eunkyoungkim | 4:68cb56ba60c6 | 29 | fprintf(fp,"%s", str); |
eunkyoungkim | 4:68cb56ba60c6 | 30 | fclose(fp); |
eunkyoungkim | 4:68cb56ba60c6 | 31 | |
eunkyoungkim | 4:68cb56ba60c6 | 32 | printf("Reading from SD card...\r\n"); |
eunkyoungkim | 4:68cb56ba60c6 | 33 | fp = fopen("/sd/mydir/sdtest.txt", "r"); |
eunkyoungkim | 4:68cb56ba60c6 | 34 | if (fp != NULL) { |
eunkyoungkim | 4:68cb56ba60c6 | 35 | fgets(str,MAX_SIZE,fp); |
eunkyoungkim | 4:68cb56ba60c6 | 36 | printf("%s", str); |
eunkyoungkim | 4:68cb56ba60c6 | 37 | printf("\r\n"); |
eunkyoungkim | 4:68cb56ba60c6 | 38 | fclose(fp); |
eunkyoungkim | 4:68cb56ba60c6 | 39 | } else { |
eunkyoungkim | 4:68cb56ba60c6 | 40 | printf("failed!\n"); |
eunkyoungkim | 4:68cb56ba60c6 | 41 | } |
eunkyoungkim | 4:68cb56ba60c6 | 42 | |
mbed_official | 0:bdbd3d6fc5d5 | 43 | } |