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
Diff: main.cpp
- Revision:
- 2:86a01df5c8ac
- Parent:
- 1:63277c702117
- Child:
- 3:47f18e0357e4
--- a/main.cpp Thu Oct 24 08:59:14 2013 +0000 +++ b/main.cpp Mon Feb 10 09:53:52 2014 +0000 @@ -1,32 +1,72 @@ +/* + main.cpp + 2014 Copyright (c) Seeed Technology Inc. All right reserved. + + Author:lawliet zou(lawliet.zou@gmail.com) + 2014-02-10 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include "mbed.h" #include "SDFileSystem.h" - + /* -FRDM KL25Z with Seeed SD Card Shield V4 -Connections have to be added between the SD Card Shield -digital connector pins and the SPI connector pins as follows: -Signal Digital SPI -MOSI D11 4 -MISO D12 1 -SCK D13 3 -/CS D4 + SEEED ARCH PRO and SEEED ARCH with Seeed SD Card Shield V4.0 + + Digital Pin 4 which is P1_18 on Seeeduino ARCH and P2_2 on + Seeeduino ARCH Pro has been used as PIN_CS and should not be + used any more! pin match is as follow. Have fun! */ -//SDFileSystem sd(PTD2, PTD3, PTD1, PTA4, "sd"); // MOSI, MISO, SCK, CS -SDFileSystem sd(D11, D12, D13, D4, "sd"); // MOSI, MISO, SCK, CS +//#define SEEEDUINO_ARCH +#define SEEEDUINO_ARCH_PRO + +#if defined(SEEEDUINO_ARCH) +#define PIN_MOSI P1_22 +#define PIN_MISO P1_21 +#define PIN_SCK P1_20 +//#define PIN_CS P1_23 +#define PIN_CS P1_18 +#elif defined(SEEEDUINO_ARCH_PRO) +#define PIN_MOSI P0_18 +#define PIN_MISO P0_17 +#define PIN_SCK P0_15 +//#define PIN_CS P0_16 +#define PIN_CS P2_2 +#else +#define PIN_MOSI P1_22 +#define PIN_MISO P1_21 +#define PIN_SCK P1_20 +#define PIN_CS P1_23 +#endif + +SDFileSystem sd(PIN_MOSI, PIN_MISO, PIN_SCK, PIN_CS, "sd"); // MOSI, MISO, SCK, CS Serial pc(USBTX, USBRX); - -int main() { - pc.printf("Hello World!\n"); - + +int main() +{ + pc.printf("Hello World!\n"); + mkdir("/sd/mydir", 0777); - + FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); if(fp == NULL) { pc.printf("Could not open file for write\n"); } fprintf(fp, "Hello fun SD Card World!"); - fclose(fp); - + fclose(fp); + pc.printf("Goodbye World!\n"); }