Powering device from ATTINY84 pin

Hi

I have a project that uses an ATTINY84 and an ADXL362 accelerometer.

Because the ADXL can give false readings in the case of a brownout, and can only recover through a power disconnect and reconnect, I want to power it from one of the ATTINY pins. This would allow me to switch the ADXL off before a brownout occurs.

It works, in the sense that the ADXL is getting power, but at the cost of the entire setup drawing far too much power, around 30mA continuously.

I am running everything at ~3.5V (from a LIPO battery)

So I define

const int powerforadxl = 9; //PA1

in setup() I have

pinMode (powerforadxl, OUTPUT);

and to turn the ADXL on I have
digitalWrite(powerforadxl, HIGH);

However, as soon as I configure the pin for OUTPUT, the current rockets, even before I do the digitalWrite.

Any ideas why this should be? The ADXL itself should not consume more than 3uA, and in other configurations, where I have powered it directly from the battery it does not. It appears that the act of configuring the pin as an OUTPUT causes the ATTINY to consume the extra current.

Can you measure the current between the Arduino pin and the ADXL power pin? Which direction is this 30mA current flowing? Is the Arduino sinking the current?

When an Arduino pin is set to OUTPUT, it defaults to LOW. Maybe the ADXL is being parasitically powered from its other pins (MISO/MOSI/SCK etc), and current is then flowing out of its power pin and being shorted to ground by the Arduino pin, hence the high current.

Perhaps you can prevent this by powering-up the ADXL before any other pins are set to OUTPUT, e.g. before SPI.begin() etc. To de-power the ADXL, you would have to ensure that any other pins that could parasitically power the ADXL are set back to INPUT before powering down.

Another option would be a diode between the Arduino pin and the ADXL's power pin. Choose a diode with a low voltage drop. Some are only 0.2V, whereas most are 0.7V.

Thanks for the ideas. A difficulty is that both chips are on a PCB, v close, with a tiny trace connecting them, which means to measure the current or insert a diode is going to require some heroic soldering.

Later, I will try your first idea of powering up the ADXL first.
I don't really need to depower the ADXL at any stage. If I end up in a brownout situation, I can reset the ATTINY manually, which will - I think - cause a momentary loss of power to the ADXL and reset it.

Please post code and complete circuit diagram. That'll be quite enlightening.

PaulRB - looks like you were right. I configured the pin as OUTPUT and set it to HIGH as the first thing in setup(), and the current has drastically reduced. Fingers crossed. Many thanks

robertjenkins:
the current has drastically reduced

Even a few microseconds of shorting could shorten the life of the ADXL and Arduino. Post a schematic and we may be able to spot an easy way to avoid that.

robertjenkins:
PaulRB - looks like you were right. I configured the pin as OUTPUT and set it to HIGH as the first thing in setup(), and the current has drastically reduced. Fingers crossed. Many thanks

Make sure to get that order correct: first digitalWrite(pin, HIGH), then pinMode(pin, OUTPUT). Otherwise the pin will be OUTPUT, LOW for about 3 µs.