for logging of environmental data, I am using a MicroSD card adapter (no brand name, eBay, China) and a 4GB Intenso SD card. I want to read data and write it to the SD card once every 10 minutes. Power consumption needs to be as low as possible.
Between the measurement points, I switch off the power supply to my sensor and SD card adapter using an NPN transistor (BC547B, 2N3904, 2SC945) and put my controller to sleep using jeelib. Everything works fine!
But I realized, that even during sleep, still 1mA of current is drawn. This disappears, when I remove the SCK connection between the Arduino and the SD controller. Doesn't sound like a lot, but for my purposes, it's a major concern (when SCK is removed, I'm around 6µA during sleep).
Is it possible to switch the SCK signal off during sleep to save that last bit of power?
In case it matters, I am using the SdFat library to write to SD. Initialization is done before each write. I figured, this would be necessary because of the poweroff of 10 minutes. Here's the function:
#include <SdFat.h>
const int chipSelect = 10;
String outfilename = "Bienen.log";
[...]
int writeToFile(String outfilename, String writestring) {
SdFat SD;
if (!SD.begin(chipSelect)) {
#ifdef DEBUG
Serial.println("Card failed, or not present");
error_signal();
#endif
} else {
#ifdef DEBUG
Serial.println("card initialized.");
#endif
}
File outfile = SD.open(outfilename.c_str(), FILE_WRITE);
#ifdef DEBUG
Serial.println(outfile);
#endif
if (outfile) {
outfile.println(writestring);
outfile.close();
#ifdef DEBUG
Serial.println("Wrote successfully.");
ok_signal();
#endif
return 0;
} else {
#ifdef DEBUG
Serial.println("Writing failed.");
error_signal();
#endif
return 1;
}
}
ok_signal() and error_signal() are merely functions to flash an LED.
EDIT: Thanks for your reply! I tried the code snippets
SPCR &= ~_BV(SPE)
and
SPCR |= _BV(SPE)
at the appropriate places, although I did not understand them. There was, however, no change in power consumption - SCK still seems to run.
I could not adapt the physical changes detailed in the suggested wordpress article, as the adapter there is quite different from my microSD adapter, and I know too little about hardware to adapt the author's suggestions. It looks and sounds quite promising though ...
Thanks for your time! Any help is greatly appreciated!
SPCR &= ~_BV(SPE)
), and set the pin to LOW. Then when writing, re-enable SPI (SPCR |= _BV(SPE)
).