a demo code to use Seeed SD Card shield V4.0 with Seeeduino-Arch or Seeeduino-Arch-Pro
Dependencies: SDFileSystem mbed
Fork of SDFileSystem_HelloWorld by
main.cpp@2:86a01df5c8ac, 2014-02-10 (annotated)
- Committer:
- lawliet
- Date:
- Mon Feb 10 09:53:52 2014 +0000
- Revision:
- 2:86a01df5c8ac
- Parent:
- 1:63277c702117
- Child:
- 3:47f18e0357e4
Initial Version (Demo of Seeeduino SD Card Shield)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 2:86a01df5c8ac | 1 | /* |
lawliet | 2:86a01df5c8ac | 2 | main.cpp |
lawliet | 2:86a01df5c8ac | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 2:86a01df5c8ac | 4 | |
lawliet | 2:86a01df5c8ac | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
lawliet | 2:86a01df5c8ac | 6 | 2014-02-10 |
lawliet | 2:86a01df5c8ac | 7 | |
lawliet | 2:86a01df5c8ac | 8 | This library is free software; you can redistribute it and/or |
lawliet | 2:86a01df5c8ac | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 2:86a01df5c8ac | 10 | License as published by the Free Software Foundation; either |
lawliet | 2:86a01df5c8ac | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 2:86a01df5c8ac | 12 | |
lawliet | 2:86a01df5c8ac | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 2:86a01df5c8ac | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 2:86a01df5c8ac | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 2:86a01df5c8ac | 16 | Lesser General Public License for more details. |
lawliet | 2:86a01df5c8ac | 17 | |
lawliet | 2:86a01df5c8ac | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 2:86a01df5c8ac | 19 | License along with this library; if not, write to the Free Software |
lawliet | 2:86a01df5c8ac | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 2:86a01df5c8ac | 21 | */ |
mbed_official | 0:bdbd3d6fc5d5 | 22 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 23 | #include "SDFileSystem.h" |
lawliet | 2:86a01df5c8ac | 24 | |
pampt | 1:63277c702117 | 25 | /* |
lawliet | 2:86a01df5c8ac | 26 | SEEED ARCH PRO and SEEED ARCH with Seeed SD Card Shield V4.0 |
lawliet | 2:86a01df5c8ac | 27 | |
lawliet | 2:86a01df5c8ac | 28 | Digital Pin 4 which is P1_18 on Seeeduino ARCH and P2_2 on |
lawliet | 2:86a01df5c8ac | 29 | Seeeduino ARCH Pro has been used as PIN_CS and should not be |
lawliet | 2:86a01df5c8ac | 30 | used any more! pin match is as follow. Have fun! |
pampt | 1:63277c702117 | 31 | */ |
pampt | 1:63277c702117 | 32 | |
lawliet | 2:86a01df5c8ac | 33 | //#define SEEEDUINO_ARCH |
lawliet | 2:86a01df5c8ac | 34 | #define SEEEDUINO_ARCH_PRO |
lawliet | 2:86a01df5c8ac | 35 | |
lawliet | 2:86a01df5c8ac | 36 | #if defined(SEEEDUINO_ARCH) |
lawliet | 2:86a01df5c8ac | 37 | #define PIN_MOSI P1_22 |
lawliet | 2:86a01df5c8ac | 38 | #define PIN_MISO P1_21 |
lawliet | 2:86a01df5c8ac | 39 | #define PIN_SCK P1_20 |
lawliet | 2:86a01df5c8ac | 40 | //#define PIN_CS P1_23 |
lawliet | 2:86a01df5c8ac | 41 | #define PIN_CS P1_18 |
lawliet | 2:86a01df5c8ac | 42 | #elif defined(SEEEDUINO_ARCH_PRO) |
lawliet | 2:86a01df5c8ac | 43 | #define PIN_MOSI P0_18 |
lawliet | 2:86a01df5c8ac | 44 | #define PIN_MISO P0_17 |
lawliet | 2:86a01df5c8ac | 45 | #define PIN_SCK P0_15 |
lawliet | 2:86a01df5c8ac | 46 | //#define PIN_CS P0_16 |
lawliet | 2:86a01df5c8ac | 47 | #define PIN_CS P2_2 |
lawliet | 2:86a01df5c8ac | 48 | #else |
lawliet | 2:86a01df5c8ac | 49 | #define PIN_MOSI P1_22 |
lawliet | 2:86a01df5c8ac | 50 | #define PIN_MISO P1_21 |
lawliet | 2:86a01df5c8ac | 51 | #define PIN_SCK P1_20 |
lawliet | 2:86a01df5c8ac | 52 | #define PIN_CS P1_23 |
lawliet | 2:86a01df5c8ac | 53 | #endif |
lawliet | 2:86a01df5c8ac | 54 | |
lawliet | 2:86a01df5c8ac | 55 | SDFileSystem sd(PIN_MOSI, PIN_MISO, PIN_SCK, PIN_CS, "sd"); // MOSI, MISO, SCK, CS |
pampt | 1:63277c702117 | 56 | Serial pc(USBTX, USBRX); |
lawliet | 2:86a01df5c8ac | 57 | |
lawliet | 2:86a01df5c8ac | 58 | int main() |
lawliet | 2:86a01df5c8ac | 59 | { |
lawliet | 2:86a01df5c8ac | 60 | pc.printf("Hello World!\n"); |
lawliet | 2:86a01df5c8ac | 61 | |
mbed_official | 0:bdbd3d6fc5d5 | 62 | mkdir("/sd/mydir", 0777); |
lawliet | 2:86a01df5c8ac | 63 | |
mbed_official | 0:bdbd3d6fc5d5 | 64 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 65 | if(fp == NULL) { |
pampt | 1:63277c702117 | 66 | pc.printf("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 67 | } |
mbed_official | 0:bdbd3d6fc5d5 | 68 | fprintf(fp, "Hello fun SD Card World!"); |
lawliet | 2:86a01df5c8ac | 69 | fclose(fp); |
lawliet | 2:86a01df5c8ac | 70 | |
pampt | 1:63277c702117 | 71 | pc.printf("Goodbye World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 72 | } |