Reducing current draw from SD card

Hello

I have a project which has a nrf24l01 RF receiver, and also an SD card. I want to compare the data received from the nrf with data previously stored on the card. I only want the SD card to be “active” when doing this comparison. The rest of the time I would like it to be in some kind of sleep mode. Actually, when waiting, the card draws about 20mA. When it’s reading data it goes down to about 0.6mA. Here’s a simplified version of the sketch.

#include <SD.h>
#include <nRF24L01.h>
#include <RF24.h>
File myFile;
const int chipSelect = 4;

#define CE_PIN   7
#define CSN_PIN 10
const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN);

byte receivedByteArray[13];
bool newData = false;

void setup()
{
  Serial.begin(9600);
  pinMode(A4, OUTPUT);
  digitalWrite(A4, 0);


  pinMode(SS, OUTPUT);
  if (!SD.begin(chipSelect))   Serial.println("initialization failed!");
  else Serial.println("initialization successful");

  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.openReadingPipe(1, thisSlaveAddress);
  radio.startListening();

}

void loop()
{
  while (!radio.available()) {} //i.e. do nothing until something comes in over the radio 
  if ( radio.available() ) {
    Serial.println("radio available");
    radio.read( &receivedByteArray, sizeof(receivedByteArray) );
    newData = true;
    myFile = SD.open("test.txt");
    char c;
    while ((c = myFile.read()) != '*') Serial.println(c); //this is just dummy code - will actually will be comparing contents of receivedByteArray to the card
    myFile.close();
  }
}

As far as I can see, the card isn’t doing anything while waiting for a radio burst, but it draws an even higher current than when being read. What am I doing wrong?

Ideally, when there is no card in the reader at all, I would like it to shut down altogether or go into some kind of deep sleep mode, but I don’t know whether this is possible.

Thanks.

I remember this coming up before, and I think the suggested solution was to switch over to Bill Greiman's SDFat.h library. SanDisk SD cards, and perhaps others, are supposed to have an automatic sleep mode when idle, but that will not function properly unless the card has been properly initialized, and SD.h apparently does not do that.

If you are using a full-size SD card module, another possibility is that the module is designed for 3.3V systems, and doesn't work properly with a 5V Adruino. You might post a link to the module you're using, or a picture of it. This shouldn't be an issue if it's a microSD card module.

Thanks. It's a micro SD card and everything is 3.3V on an Arduino mini pro clone. I will try with the SDfat library (although I have done that before and didn't see a difference but I may have been doing something wrong). I am wondering whether the issue is that the card reader is sharing the SPI pins with the NRF24L01. I believe you cannot change the SPI pin assignment with the standard SD library but possibly can with SDfat and also maybe with the Adafruit SD library.

I don't know what to suggest. Here's something I found on Google searching on SD card sleep mode:

I don't know if anything there is relevant, but there's link in answer #1 back to an old thread here.

By the way, I don't think it makes sense that current would drop to below 1mA when reading. How are you measuring that?

You could also use a transistor to switch the GND of the SD-card module. This would be effective when the SD card is idle for "longer periods". Just be sure that the SD-card is properly unmounted / finalized and files are flushed before cutting the GND.

ShermanP:
How are you measuring that?

With a multimeter. It might be averaging out fluctuations of course.

Thanks for the link. It at least suggests that conflict between different SPI devices may not be the issue (I can't diconnect the NRF on mine because it's hardwired on the PCB).

Danois90:
You could also use a transistor to switch the GND of the SD-card module.

Yes it might come to that.