mbed sd
Dependencies: SDFileSystem mbed
main.cpp@1:456047999cb0, 2016-07-15 (annotated)
- Committer:
- jh_ndm
- Date:
- Fri Jul 15 08:03:23 2016 +0000
- Revision:
- 1:456047999cb0
- Parent:
- 0:27143f32cefd
DFRobot SD
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jh_ndm | 0:27143f32cefd | 1 | #include "mbed.h" |
jh_ndm | 0:27143f32cefd | 2 | #include "SDFileSystem.h" |
jh_ndm | 1:456047999cb0 | 3 | #define LEN 2048 |
jh_ndm | 0:27143f32cefd | 4 | SDFileSystem sd(PA_14, PA_13, PA_12, PA_11, "sd"); // the pinout on the mbed Cool Components workshop board SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd"); |
jh_ndm | 0:27143f32cefd | 5 | //SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd"); |
jh_ndm | 0:27143f32cefd | 6 | Serial uart1(PA_13,PA_14); |
jh_ndm | 1:456047999cb0 | 7 | FILE *fp; |
jh_ndm | 1:456047999cb0 | 8 | char buf[LEN]; |
jh_ndm | 0:27143f32cefd | 9 | int main() { |
jh_ndm | 1:456047999cb0 | 10 | uart1.baud(9600); |
jh_ndm | 1:456047999cb0 | 11 | uart1.printf("SD Card FAT FileSystem Testing....\r\n"); |
jh_ndm | 0:27143f32cefd | 12 | |
jh_ndm | 0:27143f32cefd | 13 | mkdir("/sd/mydir", 0777); |
jh_ndm | 0:27143f32cefd | 14 | |
jh_ndm | 1:456047999cb0 | 15 | if((fp = fopen("/sd/mydir/sdtest.txt", "w")) == NULL){ |
jh_ndm | 1:456047999cb0 | 16 | error("Could not open file for write\r\n"); |
jh_ndm | 1:456047999cb0 | 17 | return -1; |
jh_ndm | 0:27143f32cefd | 18 | } |
jh_ndm | 1:456047999cb0 | 19 | fprintf(fp, "DFRobot Test String ABCDEFG......\r\n"); |
jh_ndm | 0:27143f32cefd | 20 | fclose(fp); |
jh_ndm | 1:456047999cb0 | 21 | |
jh_ndm | 1:456047999cb0 | 22 | if((fp = fopen("/sd/mydir/sdtest.txt", "r")) == NULL){ |
jh_ndm | 1:456047999cb0 | 23 | error("Could not open file for write\r\n"); |
jh_ndm | 1:456047999cb0 | 24 | return -1; |
jh_ndm | 1:456047999cb0 | 25 | } |
jh_ndm | 1:456047999cb0 | 26 | memset(buf,0,LEN); |
jh_ndm | 1:456047999cb0 | 27 | fread(buf,LEN,1,fp); |
jh_ndm | 1:456047999cb0 | 28 | buf[LEN-1] = 0; |
jh_ndm | 1:456047999cb0 | 29 | fclose(fp); |
jh_ndm | 1:456047999cb0 | 30 | uart1.printf("------------read sdtest.txt-----------\r\n"); |
jh_ndm | 1:456047999cb0 | 31 | uart1.printf("%s",buf); |
jh_ndm | 1:456047999cb0 | 32 | uart1.printf("------------end-----------\r\n"); |
jh_ndm | 0:27143f32cefd | 33 | } |