Sd cards works, then stops

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
ollie
Posts: 6
Joined: Tue Aug 20, 2013 11:03 am

Sd cards works, then stops

Post by ollie » Tue Aug 20, 2013 11:08 am

I am using the ethermega for a data logger project but it seems to be failing me.

As my project seems to be having difficulty i have gone back to basic SD card info etc to test. My ethermega boots up fine, shows me all the files on the card, reads writes etc without any issues as it has been doing. Remove the usb from the pc, wait then plug it back in and i get initialisation failure and it will not work again till i reload the same sketch and it works perfect until i remove the usb and plug it back in....

Ideas?

ollie
Posts: 6
Joined: Tue Aug 20, 2013 11:03 am

Re: Sd cards works, then stops

Post by ollie » Tue Aug 20, 2013 11:10 am

oh and i have tried different cards with the exact same result

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Sd cards works, then stops

Post by andrew » Wed Aug 21, 2013 12:34 am

Could you please post your sketch, we'll have a look.

ollie
Posts: 6
Joined: Tue Aug 20, 2013 11:03 am

Re: Sd cards works, then stops

Post by ollie » Wed Aug 21, 2013 12:58 am

My project code is about 1100 lines but it happens on a basic sketch here. After I posted it last night it worked on and off intermittently but I could not get it to work. I'm wondering if the board is malfunctioning.

Code: Select all

/*
  SD card test
  
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
    
The circuit:
  * SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
          Pin 4 used here for consistency with other Arduino examples


created  28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
*/
// include the SD library:
#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 = 4;   

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(53, OUTPUT);     // change this to 53 on a mega


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!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?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
 
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

 
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
 
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {
 
}

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Sd cards works, then stops

Post by angusgr » Wed Aug 21, 2013 5:17 am

Hi ollie,

That sketch certainly works fine for me on the EtherMega I have here.

Is there anything else attached to the EtherMega? Any potential problems with the USB hookup?

That's all I can think of apart from trying different cards, which you've already done. If none of this rings a bell, drop us a line - support at freetronics.com.

- Angus

ollie
Posts: 6
Joined: Tue Aug 20, 2013 11:03 am

Re: Sd cards works, then stops

Post by ollie » Wed Aug 21, 2013 5:27 am

Thanks angus. The only now connected is a header pin in the i2c prototype area which is not connected to anything. That sketch works great when it wants to but I can't even get it to consistently fail or succeed.

niels
Posts: 7
Joined: Thu Aug 22, 2013 12:43 am

Re: Sd cards works, then stops

Post by niels » Thu Aug 22, 2013 2:20 pm

Hi Ollie,

I've had some similar behaviour on my EtherTen when the power supply it was connected to wasn't able to supply enough current.

Can you check the voltages on the supply input with your EtherMega connected?
Does your sketch start properly if you press the reset button after plugging it in?
Can you try to power it from a DC supply instead of USB?

Cheers,
Niels

ollie
Posts: 6
Joined: Tue Aug 20, 2013 11:03 am

Re: Sd cards works, then stops

Post by ollie » Sat Aug 24, 2013 1:06 pm

Thanks for that I will take a look but i do get the error running it from several different usb ports and pcs. I have changed my project to use a generic mega and a sd card for the moment without having to make any code changes.

One of the things that is interesting is that when my Ethermega works, it starts up fine but when it boots (with nothing attached) and the LED 13 turns on, the unit fails. There is no reference in my code regarding this.... Anyway....

niels
Posts: 7
Joined: Thu Aug 22, 2013 12:43 am

Re: Sd cards works, then stops

Post by niels » Wed Aug 28, 2013 12:01 am

Hi Ollie,

The bootloader is almost certainly what's causing LED 13 to flash.

The following page has some more info on it, specifically the section titled 'Low Voltage from USB'.

http://www.freetronics.com/pages/usb-power-and-reset

Cheers,
Niels

ollie
Posts: 6
Joined: Tue Aug 20, 2013 11:03 am

Re: Sd cards works, then stops

Post by ollie » Wed Aug 28, 2013 1:26 am

niels wrote:Hi Ollie,

The bootloader is almost certainly what's causing LED 13 to flash.

The following page has some more info on it, specifically the section titled 'Low Voltage from USB'.

http://www.freetronics.com/pages/usb-power-and-reset

Cheers,
Niels
Thanks Niels

I will look at that soon. I need it to run this weekend so I have worked around above.

Post Reply