0

SD card initialization failure using Mega 2560 / gps ultra d
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SD card initialization failure using Mega 2560 / gps ultra d

by jtabatch on Wed Aug 04, 2021 6:41 pm

Setup is Mega 2560 with GPS ultra data logger shield. Shield switch is set to "Direct" and GPS is working. Using Cardinfo example as a test bench with chipSelect = 10. SD card is good. Get "SD Card initialization failure" on serial output. Also followed recommended download of SD library per online setup instructions. Sort of at the end of my rope here . Below is a snipit of Cardinfo code.

#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}


Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(SS, OUTPUT);


// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
while (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
}

jtabatch
 
Posts: 25
Joined: Thu Sep 29, 2016 3:31 pm

Re: SD card initialization failure using Mega 2560 / gps ult

by adafruit_support_bill on Wed Aug 04, 2021 6:58 pm

Please post photos showing all your soldering to the board.

adafruit_support_bill
 
Posts: 81936
Joined: Sat Feb 07, 2009 10:11 am

Re: SD card initialization failure using Mega 2560 / gps ult

by jtabatch on Wed Aug 04, 2021 9:00 pm

photos enclosed. Thanks
Attachments
gps_mega_2560.pdf
solder connections
(307.95 KiB) Downloaded 5 times

jtabatch
 
Posts: 25
Joined: Thu Sep 29, 2016 3:31 pm

Re: SD card initialization failure using Mega 2560 / gps ult

by adafruit_support_bill on Thu Aug 05, 2021 5:47 am

The soldering looks good. For the Mega, you need to use Soft SPI.
See the compatibility guide here: https://learn.adafruit.com/adafruit-shi ... s-642938-6

adafruit_support_bill
 
Posts: 81936
Joined: Sat Feb 07, 2009 10:11 am

Re: SD card initialization failure using Mega 2560 / gps ult

by jtabatch on Thu Aug 05, 2021 12:48 pm

hi - thanks for the reply. I followed your instructions and set the dip switch to soft and jumped pins 7/8 to D18 and 19. Checked Sd2PinMap and Sd2card.h and for the ATmega2560 the lines had already been adjusted . I am running shield_sdlog and the card is still not initializing. I am using a 32 G card that had been formatted . Shield/card works on Uno but Uno does not have enough memory for what I want to do.

Justin

jtabatch
 
Posts: 25
Joined: Thu Sep 29, 2016 3:31 pm

Re: SD card initialization failure using Mega 2560 / gps ult

by adafruit_support_bill on Thu Aug 05, 2021 12:58 pm

Code: Select all | TOGGLE FULL SIZE
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Mega

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 20;
uint8_t const SCL_PIN = 21;

// SPI port
uint8_t const SS_PIN = 53;
uint8_t const MOSI_PIN = 51;
uint8_t const MISO_PIN = 50;
uint8_t const SCK_PIN = 52;


sdPinMap defines the hardware SPI pins for the Mega. If you look, you will see that those pins are on the Mega extended headers and have no connection to the shield.

Please follow the instructions in the link above to use software SPI with the Mega.

adafruit_support_bill
 
Posts: 81936
Joined: Sat Feb 07, 2009 10:11 am

Re: SD card initialization failure using Mega 2560 / gps ult

by jtabatch on Thu Aug 05, 2021 1:15 pm

Ok - still not working

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Mega

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 20;
uint8_t const SCL_PIN = 21;

// SPI port

uint8_t const SS_PIN = 10;
uint8_t const MOSI_PIN = 11;
uint8_t const MISO_PIN = 12;
uint8_t const SCK_PIN = 13;

/*
uint8_t const SS_PIN = 53;
uint8_t const MOSI_PIN = 51;
uint8_t const MISO_PIN = 50;
uint8_t const SCK_PIN = 52;
*/

jtabatch
 
Posts: 25
Joined: Thu Sep 29, 2016 3:31 pm

Re: SD card initialization failure using Mega 2560 / gps ult

by adafruit_support_bill on Thu Aug 05, 2021 1:27 pm

The preferred method is not to edit sdPinMap, but to specify the pins in your call to the 'begin()' function:

as in:

Code: Select all | TOGGLE FULL SIZE
  begin(10,11,12,13);

adafruit_support_bill
 
Posts: 81936
Joined: Sat Feb 07, 2009 10:11 am

Re: SD card initialization failure using Mega 2560 / gps ult

by jtabatch on Thu Aug 05, 2021 1:40 pm

Lol - wish you had told me that in the beginning . At least it's initializing so over came first hurdle .

Thanks for the help.

Justin

jtabatch
 
Posts: 25
Joined: Thu Sep 29, 2016 3:31 pm

Please be positive and constructive with your questions and comments.