Pages: [1]   Go Down
Author Topic: deinitialization for SD library  (Read 1711 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At use SD card in devices with a battary power, the great value has consumption of energy by the card which can make 40-80 ma.
For reduction of consumption of energy by a SD card it is necessary to switch it in IDLE state when it is not used.
For this purpose to add to SD library a method making deinitialization cards and SPI:

in file Sd2Card.h to add the bolded:


/**
 * \class Sd2Card
 * \brief Raw access to SD and SDHC flash memory cards.
 */
class Sd2Card {
 public:
  /** Construct an instance of Sd2Card. */
  Sd2Card(void) : errorCode_(0), inBlock_(0), partialBlockRead_(0), type_(0) {}
  uint32_t cardSize(void);
  uint8_t erase(uint32_t firstBlock, uint32_t lastBlock);
  uint8_t eraseSingleBlockEnable(void);
  /**
   * \return error code for last error. See Sd2Card.h for a list of error codes.
   */
  uint8_t errorCode(void) const {return errorCode_;}
  /** \return error data for last error. */
  uint8_t errorData(void) const {return status_;}
  /**
   * Initialize an SD flash memory card with default clock rate and chip
   * select pin.  See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
   */
  uint8_t init(void) {
    return init(SPI_FULL_SPEED, SD_CHIP_SELECT_PIN);
  }
  /**
   * Initialize an SD flash memory card with the selected SPI clock rate
   * and the default SD chip select pin.
   * See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).
   */
  uint8_t init(uint8_t sckRateID) {
    return init(sckRateID, SD_CHIP_SELECT_PIN);
  }
  uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin);

  /*
   * deinitialization SD flash memory and stop SPI
   */
  void stop();




In file Sd2Card.cpp:


void Sd2Card::stop()
{
     // command to go idle in SPI mode
     status_ = cardCommand(CMD0, 0);
#ifndef SOFTWARE_SPI
     SPCR &= ~_BV(SPE);
#endif
}





And also to add this method in a wrapper. In file SD.h:


class SDClass {

private:
  // These are required for initialisation and use of sdfatlib
  Sd2Card card;
  SdVolume volume;
  SdFile root;
 
public:
  // This needs to be called to set up the connection to the SD card
  // before other methods are used.
  boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);

  void stop();




In file SD.spp:

void SDClass::stop()
{
   card.stop();
}


Now when the card isn't necessary it is possible to cause this method. See example:

Code:
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    SD.stop();
    return;
  }

  // Using SD card....
 
  // deinitialize SD card
  SD.stop();
 

The card in IDLE-stae will consume considerably smaller current that will lead to the big economy of energy of the battery.


P.S.
Excuse for my bad English

Best regards,
Alexander (Azimutx)
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 227
Posts: 14010
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

makes sense for some apps, have you checked the author of the library? or - http://code.google.com/p/beta-lib/issues/list
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Azimutx for this. The major hurdle for the data logger that i am working on was the sd card power consumption. I was initially going to use an opticoupler on the cards ground. This saves me the effort, and the pin.
Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1673
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What type card are you using?

Modern cards draw less than 1 ma when initialized and idle.  I tested a Transcend 8 GB class 6 card and it draws less than 1 ma before and after it is initialized.  It draws over 30 ma during read access and more than 40 ma for writes.

An older SanDisk 1 GB card, manufactured in 2006, draws 1 ma before initialization and 8 ma when initialized.  I think this card was designed long before 2006.
Logged

Pages: [1]   Go Up
Jump to: