SD Read
Dependencies: SDFileSystem mbed
Fork of AVC_My_sdcard_read by
main.cpp@0:1a8003e5f568, 2014-11-20 (annotated)
- Committer:
- gerardo_carmona
- Date:
- Thu Nov 20 21:07:00 2014 +0000
- Revision:
- 0:1a8003e5f568
- Child:
- 1:cb4b883237fd
SD Example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gerardo_carmona | 0:1a8003e5f568 | 1 | /* |
gerardo_carmona | 0:1a8003e5f568 | 2 | My SDcard |
gerardo_carmona | 0:1a8003e5f568 | 3 | |
gerardo_carmona | 0:1a8003e5f568 | 4 | Trying to save data in a file, but instead of replacing old data |
gerardo_carmona | 0:1a8003e5f568 | 5 | i would like to append it. |
gerardo_carmona | 0:1a8003e5f568 | 6 | |
gerardo_carmona | 0:1a8003e5f568 | 7 | */ |
gerardo_carmona | 0:1a8003e5f568 | 8 | |
gerardo_carmona | 0:1a8003e5f568 | 9 | #include "mbed.h" |
gerardo_carmona | 0:1a8003e5f568 | 10 | #include "SDFileSystem.h" |
gerardo_carmona | 0:1a8003e5f568 | 11 | |
gerardo_carmona | 0:1a8003e5f568 | 12 | // Puertos |
gerardo_carmona | 0:1a8003e5f568 | 13 | DigitalOut rled(LED_RED); |
gerardo_carmona | 0:1a8003e5f568 | 14 | DigitalOut gled(LED_GREEN); |
gerardo_carmona | 0:1a8003e5f568 | 15 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
gerardo_carmona | 0:1a8003e5f568 | 16 | |
gerardo_carmona | 0:1a8003e5f568 | 17 | // Objetos |
gerardo_carmona | 0:1a8003e5f568 | 18 | FILE *fp; |
gerardo_carmona | 0:1a8003e5f568 | 19 | |
gerardo_carmona | 0:1a8003e5f568 | 20 | char buffer[1024]; |
gerardo_carmona | 0:1a8003e5f568 | 21 | |
gerardo_carmona | 0:1a8003e5f568 | 22 | int main(){ |
gerardo_carmona | 0:1a8003e5f568 | 23 | rled = 1; |
gerardo_carmona | 0:1a8003e5f568 | 24 | wait(1); |
gerardo_carmona | 0:1a8003e5f568 | 25 | while (true) { |
gerardo_carmona | 0:1a8003e5f568 | 26 | FILE *fp = fopen("/sd/test.txt", "r"); |
gerardo_carmona | 0:1a8003e5f568 | 27 | if (fp == 0){ |
gerardo_carmona | 0:1a8003e5f568 | 28 | printf("Could not open file\n"); |
gerardo_carmona | 0:1a8003e5f568 | 29 | }else{ |
gerardo_carmona | 0:1a8003e5f568 | 30 | int x; |
gerardo_carmona | 0:1a8003e5f568 | 31 | while ((x = fgetc(fp)) != EOF){ |
gerardo_carmona | 0:1a8003e5f568 | 32 | printf("%c", x); |
gerardo_carmona | 0:1a8003e5f568 | 33 | } |
gerardo_carmona | 0:1a8003e5f568 | 34 | fclose(fp); |
gerardo_carmona | 0:1a8003e5f568 | 35 | } // IF |
gerardo_carmona | 0:1a8003e5f568 | 36 | wait(1); |
gerardo_carmona | 0:1a8003e5f568 | 37 | } // WHILE |
gerardo_carmona | 0:1a8003e5f568 | 38 | } // MAIN |