Go Down

Topic: SD Card and Arduino Mega (Read 4902 times) previous topic - next topic

ionito

Hi,

I am trying to connect a SD shield with Arduino Mega 1280but I was not successful. Any hint?

I made the connections as follows:

[font=Courier New]
Name            Pin at SD Shield         Arduino Mega Pin
-------------------------------------------------------------
MOSI_PIN                     11                      50
MISO_PIN                     12                      51
SCK_PIN                      13                      52
SS_PIN                       10                      53
Activation(PWR)              9                       9[/font]


Also, I made the following modification at the ...\arduino-0021\libraries\FileLogger\Spi.h file:

# define SCK_PIN  52
# define MISO_PIN  51
# define MOSI_PIN  50
# define SS_PIN  53


baum

My only though is that the FileLogger library may reference the builtin SPI library. Are the pins in all referenced libraries changed?

P18F4550

There are so many variables that can cause problems, i can tell you my working configuration though,

Im using IDE_0018 with the standard spi library and i have 10k pullups on all 4 spi pins
if your SPI.h does not already have this code then try adding it and make sure you select mega 1280 from the tools->board menu, this config works for me, hope it does for you
Code: [Select]
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
  #define SCK_PIN   52
  #define MISO_PIN  50
  #define MOSI_PIN  51
  #define SS_PIN    53
#endif

ionito

Thanks for the suggestions. Based on the last reply, I realized that I copied wrong code from somewhere and the MISO mapping is swapped with MOSI. These are the final guidelines if you want some direction to make the Arduino Mega 1280 board work with the SD Card Shield 2.1 (from Seeesdstudio.com). You can try modifications if you have a similar but not identical configuration. Also, some of the aspects below may not apply for your configuration:

Software: FileLogger library which is included at IDE v0021.

a) FAT32 is not supported - you need to format using FAT(16).

b) Some SD cards with already FAT16 do not work. However, after re-formatting them again (I used Windows XP and FAT option at the format program), they work!!

c) The SD card must be <= 2GB (that is, no SHDC cards).

d) Not all the SD cards work...
* Kingston 2GB micro SD SD-C02G with adapter does not work.
* Apacer 2GB, 60X (not a micro SD) works fine.
* Kodak 512MB works fine.
* Speedy Adata 1GB SD card works fine.

e) The file data.log MUST exist.

f) The file data.log MUST HAVE content (at least one character or a line feed)!!!!

g) In the case of my shield board, the activation is done by I/O 9, but the software states 8. I changed the software to 9 and it worked fine (assuming switch 3.3V vs. D9 in the D9 position).

h) (Only for Arduino 168/328-based) REMOVE any hardware or software which is related to Arduino I/O pins 9, 10, 11, 12, and 13.

i) Use the following code to test (concept_SD_Card_Mega.pde):
Code: [Select]

#include <FileLogger.h>
#include <mmc.h>
#include <nanofat.h>
#include <Spi.h>

int count=0;

// define the pin that powers up the SD card
#define MEM_PW 9

// variable used when reading from serial
byte inSerByte = 0;

#define MESSAGE ">>>>>>>>>>>> Ionito sucks! <<<<<<<<<<<<<<<*\r\n"

unsigned long length = sizeof(MESSAGE)-1;
byte buffer[] = MESSAGE;
boolean goAhead = true;

void setup() {               
  pinMode(2, OUTPUT);   
  Serial.begin(9600);
  pinMode(MEM_PW, OUTPUT);
  digitalWrite(MEM_PW, HIGH);
}

void loop() {
  count++;
  Serial.println(count);
  delay(1500);              // wait a second

  int result;
  if (goAhead) {
    result = FileLogger::append("data.log", buffer, length);
    Serial.print(" Result: ");
    if( result == 0) {
      Serial.println("OK");
    } else if( result == 1) {
      Serial.println("Fail initializing");
    } else if( result == 2) {
      Serial.println("Fail appending");
    }
 
    for(int i=0; i<10; i++) {
      result = FileLogger::append("data.log", buffer, length);
      Serial.print(" Result: ");
      if( result == 0) {
        Serial.println("OK");
      } else if( result == 1) {
        Serial.println("Fail initializing");
      } else if( result == 2) {
        Serial.println("Fail appending");
      }
  }
  Serial.print("Done");

  }
  goAhead = false;
}


j) Modify the file ...\arduino-0021\libraries\FileLogger\Spi.h :
Code: [Select]

...
#ifndef Spi_h
#define Spi_h

#include "WProgram.h"
#define SCK_PIN   13
#define MISO_PIN  12
#define MOSI_PIN  11
#define SS_PIN    10

#if defined(__AVR_ATmega128__) || (__AVR_ATmega1280__)
#define SCK_PIN   52
#define MISO_PIN  50
#define MOSI_PIN  51
#define SS_PIN    53
#endif
...


k) Make the following "wire connections":
[font=Courier New]
SD Card Shield V.2.1

=======================
|          3.3V   D9  |
|              ----   |
|                 *   |
|              ----   |
|             GND  o  |
|             "13" o  |
|  o  3.3V    "12" o  | 
|  o  5V      "11" o  |
|  o  GND     "10" o  | 
|  o  GND      "9" o  |
|                /
=================

Signal Name        Pin at SD Shield         Arduino Mega Pin
-------------------------------------------------------------
                          3.3V                   3.3V
                          5V                      5V  (optional)
                          GND                    GND
Activation(PWR)            9                       9 *
SS_PIN                     10                     53
MOSI_PIN                   11                     51
MISO_PIN                   12                     50
SCK_PIN                    13                     52

* optional: if the switch at the SD Card is at "3.3V" position, we do not need to use this pin. I used it because I need to "turn-on" and "off" this device.
[/font]

l) Note that I did not use pull-ups (internal or external) for the SPI lines. In order to connect the original pins "10-13" of the SD card to the pins 50-53 of the Arduino Mega board, you need to "cut" these pins and solder "jumpers" from the SD card to the pins 50-53.

Hope this helps the guys after me!!


Go Up