Hi all,
I am working on a small data logger using an adxl345 accelerometer breakout, Arduino pro mini ultra and an micro SD shield.
Accel: http://www.sparkfun.com/products/9156
MicroSD: SparkFun microSD Transflash Breakout - BOB-00544 - SparkFun Electronics
Arduino: http://www.rocketscream.com/blog/category/projects/arduino-related/mini-ultra-8-mhz-low-power-arduino-compatible-board/
I am working on the power consumption of the accelerometer and I am getting some strange readings. I have configured the appropriate registers as per the data sheet and have confirmed the device is auto sleeping by reading various status bits. According to the datasheet consumption should be around 40uA while asleep. The initialisation code is below if you would like to have a look but I think its fine...
void setupAccel() {
SPI.begin();
SPI.setDataMode(SPI_MODE3);
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
// interrupts setup
writeRegister(INT_MAP, B8(00011000)); // send all interrupts to ADXL345's INT2 pin
writeRegister(INT_ENABLE, B8(00011000)); // activity, inactivity
writeRegister(DATA_FORMAT, B8(00100001)); //invert interrupts for active low
writeRegister(BW_RATE, B8(00001001)); //set data rate
// inactivity configuration
writeRegister(TIME_INACT, 3); // 1s / LSB
writeRegister(THRESH_INACT, 3); // 62.5mg / LSB
// also working good with high movements: R_TIME_INACT=5, R_THRESH_INACT=16, R_ACT_INACT_CTL=B8(00000111)
// but unusable for a quite slow movements
// activity configuration
writeRegister(THRESH_ACT, 6); // 62.5mg / LSB
// activity and inctivity control
writeRegister(ACT_INACT_CTL, B8(11111111)); // enable activity and inactivity detection on x,y,z using ac
// set the ADXL345 in measurement and sleep Mode: this will save power while while we will still be able to detect activity
// set the Link bit to 1 so that the activity and inactivity functions aren't concurrent but alternatively activated
// set the AUTO_SLEEP bit to 1 so that the device automatically goes to sleep when it detects inactivity
writeRegister(POWER_CTL, B8(111111));
}
void writeRegister(char registerAddress, char value){
SPI.setDataMode(SPI_MODE3);
digitalWrite(CS, LOW);
SPI.transfer(registerAddress);
SPI.transfer(value);
digitalWrite(CS, HIGH);
}
void readRegister(char registerAddress, int numBytes, char * values){
SPI.setDataMode(SPI_MODE3);
char address = 0x80 | registerAddress;
if(numBytes > 1)address = address | 0x40;
digitalWrite(CS, LOW);
SPI.transfer(address);
for(int i=0; i<numBytes; i++){
values[i] = SPI.transfer(0x00);
}
digitalWrite(CS, HIGH);
}
The strange part is if I run my code with the Accelerometer and micro SD connected the power consumption of the accelerometer sits around 41uA which is perfect. However, without the SD card the consumption is about 60uA then rises to around 120uA. After a little more investigation I realised I only need to leave the SD's Data Out line connected for the power consumption to stay at 41uA.
Furthermore, I realised if I add the SD initialisation code and upload that to the board, accelerometer power consumption sits at 41uA. I can then delete the SD code and re-upload and the power stays at 41uA, even after multiple resets and power offs. However, if I eject the microSD and re-insert it the power spikes and wont return to 41uA until I re-upload the SD initialisation code. I'm using the SDFat library and the code is below.
if (!sd.init(SPI_FULL_SPEED, chipSelect)) {
Serial.println("SD ERROR");
digitalWrite(redLED, HIGH);
sd.initErrorHalt();
}
I guess seeing how I will be using the SD in my final application I could ignore this but its really been bugging me and I want to know what is happening. I also want to 'switch off' the SD when its not in use if I can. I didn't even notice this problem until I started trying to disconnect the SD.
Sorry if this is unclear, its difficult to describe the problem.
Any ideas or suggestions on what is happening here would be appreciated.
Cheers