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@3:47f18e0357e4, 2014-02-16 (annotated)
- Committer:
- lawliet
- Date:
- Sun Feb 16 03:47:41 2014 +0000
- Revision:
- 3:47f18e0357e4
- Parent:
- 2:86a01df5c8ac
version 0.1
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 | */ |
lawliet | 3:47f18e0357e4 | 22 | |
mbed_official | 0:bdbd3d6fc5d5 | 23 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 24 | #include "SDFileSystem.h" |
lawliet | 2:86a01df5c8ac | 25 | |
pampt | 1:63277c702117 | 26 | /* |
lawliet | 2:86a01df5c8ac | 27 | SEEED ARCH PRO and SEEED ARCH with Seeed SD Card Shield V4.0 |
lawliet | 2:86a01df5c8ac | 28 | |
lawliet | 2:86a01df5c8ac | 29 | Digital Pin 4 which is P1_18 on Seeeduino ARCH and P2_2 on |
lawliet | 2:86a01df5c8ac | 30 | Seeeduino ARCH Pro has been used as PIN_CS and should not be |
lawliet | 2:86a01df5c8ac | 31 | used any more! pin match is as follow. Have fun! |
pampt | 1:63277c702117 | 32 | */ |
pampt | 1:63277c702117 | 33 | |
lawliet | 3:47f18e0357e4 | 34 | #if defined(TARGET_LPC11U24) //SEEEDUINO_ARCH |
lawliet | 3:47f18e0357e4 | 35 | #define PIN_MOSI P1_22 |
lawliet | 3:47f18e0357e4 | 36 | #define PIN_MISO P1_21 |
lawliet | 3:47f18e0357e4 | 37 | #define PIN_SCK P1_20 |
lawliet | 3:47f18e0357e4 | 38 | //#define PIN_CS P1_23 |
lawliet | 3:47f18e0357e4 | 39 | #define PIN_CS P1_18 |
lawliet | 3:47f18e0357e4 | 40 | #elif defined(TARGET_LPC1768) //SEEEDUINO_ARCH_PRO |
lawliet | 3:47f18e0357e4 | 41 | #define PIN_MOSI P0_18 |
lawliet | 3:47f18e0357e4 | 42 | #define PIN_MISO P0_17 |
lawliet | 3:47f18e0357e4 | 43 | #define PIN_SCK P0_15 |
lawliet | 3:47f18e0357e4 | 44 | //#define PIN_CS P0_16 |
lawliet | 3:47f18e0357e4 | 45 | #define PIN_CS P2_2 |
lawliet | 3:47f18e0357e4 | 46 | #else //please redefine the following pins. |
lawliet | 3:47f18e0357e4 | 47 | #define PIN_MOSI |
lawliet | 3:47f18e0357e4 | 48 | #define PIN_MISO |
lawliet | 3:47f18e0357e4 | 49 | #define PIN_SCK |
lawliet | 3:47f18e0357e4 | 50 | #define PIN_CS |
lawliet | 2:86a01df5c8ac | 51 | #endif |
lawliet | 2:86a01df5c8ac | 52 | |
lawliet | 2:86a01df5c8ac | 53 | SDFileSystem sd(PIN_MOSI, PIN_MISO, PIN_SCK, PIN_CS, "sd"); // MOSI, MISO, SCK, CS |
pampt | 1:63277c702117 | 54 | Serial pc(USBTX, USBRX); |
lawliet | 2:86a01df5c8ac | 55 | |
lawliet | 2:86a01df5c8ac | 56 | int main() |
lawliet | 2:86a01df5c8ac | 57 | { |
lawliet | 2:86a01df5c8ac | 58 | pc.printf("Hello World!\n"); |
lawliet | 2:86a01df5c8ac | 59 | |
mbed_official | 0:bdbd3d6fc5d5 | 60 | mkdir("/sd/mydir", 0777); |
lawliet | 2:86a01df5c8ac | 61 | |
mbed_official | 0:bdbd3d6fc5d5 | 62 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
mbed_official | 0:bdbd3d6fc5d5 | 63 | if(fp == NULL) { |
pampt | 1:63277c702117 | 64 | pc.printf("Could not open file for write\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 65 | } |
mbed_official | 0:bdbd3d6fc5d5 | 66 | fprintf(fp, "Hello fun SD Card World!"); |
lawliet | 2:86a01df5c8ac | 67 | fclose(fp); |
lawliet | 2:86a01df5c8ac | 68 | |
pampt | 1:63277c702117 | 69 | pc.printf("Goodbye World!\n"); |
mbed_official | 0:bdbd3d6fc5d5 | 70 | } |