STRUIX Projects‎ > ‎

6: Using an SD Card with STRUIX

This tutorial describes how to build and use a micro SD card interface with the STRUIX system.


The basic connection diagram is outlined below.  It should work with most Arduino example codes that support SD card storage, including SD_RAW by Roland Riegel and the SD card library included with Arduino 0022.  Admittedely, we have not tried the Arduino SD library (yet), but it appears to be easily adaptable on first inspection.  The major change to the Arduino SD library is to remap the CS (chip select) signal to uses D8 rather than the default D10.  Happy coding!

UPDATE:  See the change notes at the end of the page, to get the Arduino 0022 SD library working with STRUIX.


A simple application using a version of SD_RAW tailored for STRUIX is included in the attachments section below.  Download and unzip the file to a subfolder in your Arduino Sketches directory.

CPU --------------  SD
D8   ========= >> CS (chip select) - part of the SPI bus *
D9   ========= >> CD (chip detect) - whether or not a card is inserted *
D10 ========= >> Not used
D11 (MOSI) ===== >> DI (Data In - from the SD card's perspective)
D12 (MISO) ===== >> DO (Data Out - from the SD card's perspective)
D13 (SCK)   ===== >> SCK (SPI bus clock)

* D8 & D9 are pulled up to VCC (+3V) by 33k resistors.

Keep in mind, the STRUIX configuration reserves D8, D9, D10, D11, D12 & D13 for SPI bus components.  For this single CPU/device combo, D8 is used as chip select.  D10 is not used in this example.  If multiple SPI devices were being controlled with this CPU, D10 could be used in addition to D8, to multiplex select up to 3 devices on the buss (3 devices + none).  If using full size SD cards, D10 could also be used to detect write protect (WP) status as well.


What you'll need:

1ea STRUIX CPU - or converted Lilypad
1ea STRUIX Protopad One
1ea Micro SD Card break out board (Like Sparkfun #BOB-00544)
1ea Single-row, breakaway header (7 places)
2ea 33k - 1/4W resistors
Misc Jumper Wire
3mm F/F metal standoffs
3mm M/F plastic standoffs
3mm Machine Screws
Double Sided Foam Tape


How to do it:

 
Start off by making the power (Vcc & GND) connections and installing the pullup resistors on the front of the ProtoPad.

The plastic standoffs are just reminders of which pads are getting connected.
 
 
Next, make connections to SCK (D13) and pullup resistors on CS (D8) and CD (D9).
 
 
On the back side, make the connections to D11 (MOSI) and D12 (MISO).
 
 

A header needs to be soldered on the micro SD card adapter.  Using a blob of adhesive putty makes it easy to get the positioning right and temporarily hold the header while the solder connection is made on the opposite side.  Perfect every time!
 
 
 
 
Apply two layers of double sided foam tape to help fix the SD card socket to the ProtoPad.

Notice how the layer on top is slightly shorter than the bottom.  This makes room for the yellow SCK jumper wire that runs under the break out board.
 
 
Install the break out board, solder the connections on the ProtoPad and you're done!
 
 
 
  


Next we'll assemble the completed SD board to the CPU:

This CPU being used is a converted Lilypad.  The outer pad holes are simply drilled out to 3mm.  If this CPU looks familiar, it's because it was used on the In-Curcuit Programmer (ISP) project.

 
Start off, by installing the foundation standoffs on the SD card board.  Use F/F metal standoffs on the top side and M/F plastic standoffs on the bottom.

The signal connections being made here are for GND and MOSI (D11).  The third leg at A4 is only for structure.
 
 

 
 

Next install F/F metal standoffs at positions VCC, D8, D9, D12 & D13.  Fasten using machine screws through the bottom side.
 
 
 
 

Finally, install the drilled out Lilypad (or STRUIX CPU) using 3mm machine screws through the top side.

Now you're ready to program the CPU with the serial programmer.
 


In the attachments section below is a version of Roland Riegel's SD_RAW, customized to work with the STRUIX configuration.  It's a simple application that will confirm the operational status and display vital statistics about the SD card.  Then the card is exercised by writing, then reading data and computing the block write duration in microseconds.

Keep in mind that this is a LOW LEVEL R/W application that will destroy any OS formatting on the SD card.  It will need to be reformatted (FAT or FAT32 most likely) to work with the SD card library included with Arduino 0022 (or other FAT library for that matter).

Change notes:
We note the following changes to the Arduino 0022 SD library to work with STRUIX.

1.  In the file Sd2PinMap.h (located in libraries\SD\utility\) locate the string "// 168 and 328 Arduinos".
Change the line below "//SPI port"
which reads:
  uint8_t const SS_PIN = 10;
to:
  uint8_t const SS_PIN = 8;  // for STRUIX

 


In all examples & applications that use the SD library: 
2.  In the setup() function, change the baud rate of
Serial.begin() to 57600
(or whatever your bootloader serial rate is)

3.  Make sure pin 8 (CS) is set to output.
(In the example codes) Below the line:
   pinMode(10, OUTPUT);

Add the line:
  pinMode(8, OUTPUT);
  
4.  Change the default CS pin.
Initialize the SD library with:
  SD.begin(8)
rather than the example default.


Č
ċ
ď
Project Struix,
Sep 11, 2011, 10:13 AM
Comments