demo code to use the SD card of Seeed Arch GPRS V2.0
Dependencies: SDFileSystem USBDevice mbed
main.cpp@0:0f3ea0944add, 2014-04-29 (annotated)
- Committer:
- lawliet
- Date:
- Tue Apr 29 12:49:33 2014 +0000
- Revision:
- 0:0f3ea0944add
Initial Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:0f3ea0944add | 1 | /* |
lawliet | 0:0f3ea0944add | 2 | main.cpp |
lawliet | 0:0f3ea0944add | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 0:0f3ea0944add | 4 | |
lawliet | 0:0f3ea0944add | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
lawliet | 0:0f3ea0944add | 6 | 2014-4-29 |
lawliet | 0:0f3ea0944add | 7 | |
lawliet | 0:0f3ea0944add | 8 | This library is free software; you can redistribute it and/or |
lawliet | 0:0f3ea0944add | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 0:0f3ea0944add | 10 | License as published by the Free Software Foundation; either |
lawliet | 0:0f3ea0944add | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 0:0f3ea0944add | 12 | |
lawliet | 0:0f3ea0944add | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 0:0f3ea0944add | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 0:0f3ea0944add | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 0:0f3ea0944add | 16 | Lesser General Public License for more details. |
lawliet | 0:0f3ea0944add | 17 | |
lawliet | 0:0f3ea0944add | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 0:0f3ea0944add | 19 | License along with this library; if not, write to the Free Software |
lawliet | 0:0f3ea0944add | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 0:0f3ea0944add | 21 | */ |
lawliet | 0:0f3ea0944add | 22 | #include "mbed.h" |
lawliet | 0:0f3ea0944add | 23 | #include "USBSerial.h" |
lawliet | 0:0f3ea0944add | 24 | #include "SDFileSystem.h" |
lawliet | 0:0f3ea0944add | 25 | |
lawliet | 0:0f3ea0944add | 26 | SDFileSystem sd(P1_22, P1_21, P1_20, P1_23, "sd"); // mosi, miso, sclk, cs |
lawliet | 0:0f3ea0944add | 27 | USBSerial pc; |
lawliet | 0:0f3ea0944add | 28 | FILE *fp; |
lawliet | 0:0f3ea0944add | 29 | |
lawliet | 0:0f3ea0944add | 30 | int main() |
lawliet | 0:0f3ea0944add | 31 | { |
lawliet | 0:0f3ea0944add | 32 | pc.printf("Initializing\r\n"); |
lawliet | 0:0f3ea0944add | 33 | |
lawliet | 0:0f3ea0944add | 34 | fp = fopen("/sd/hello.txt", "r"); |
lawliet | 0:0f3ea0944add | 35 | if (fp != NULL) { |
lawliet | 0:0f3ea0944add | 36 | fclose(fp); |
lawliet | 0:0f3ea0944add | 37 | remove("/sd/hello.txt"); |
lawliet | 0:0f3ea0944add | 38 | pc.printf("Remove an existing file with the same name\r\n"); |
lawliet | 0:0f3ea0944add | 39 | } |
lawliet | 0:0f3ea0944add | 40 | |
lawliet | 0:0f3ea0944add | 41 | fp = fopen("/sd/hello.txt", "w"); |
lawliet | 0:0f3ea0944add | 42 | if (fp == NULL) { |
lawliet | 0:0f3ea0944add | 43 | pc.printf("Unable to write the file\r\n"); |
lawliet | 0:0f3ea0944add | 44 | } else { |
lawliet | 0:0f3ea0944add | 45 | fprintf(fp, "mbed SDCard application!"); |
lawliet | 0:0f3ea0944add | 46 | fclose(fp); |
lawliet | 0:0f3ea0944add | 47 | pc.printf("File successfully written!\r\n"); |
lawliet | 0:0f3ea0944add | 48 | } |
lawliet | 0:0f3ea0944add | 49 | } |