AVR and unused pins question

Go To Last Post
4 posts / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,


If I use, say, an ATTiny 85 with the internal R/C clock, then pins 2 and 3 (XTAL1 and XTAL2) are available for use as PB3 and PB4.


The datasheet says:


Unconnected Pins
If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of
the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to
reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle
The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. In this case, the
pull-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use
an external pull-up or pull-down. Connecting unused pins directly to VCC or GND is not recommended, since this
may cause excessive currents if the pin is accidentally configured as an output.


My application uses pins 5, 6 and 7 (PB0, 1 and 2).  Two of these I have connected to VCC via a 100K resistor and one to GND through a 100K resistor (this pin drives a BJT base through a 220 ohm resistor and I want that pin to be low when it's not being driven).


So, my question is this: What should I do with the two unused crystal pins:


  • Pull up to VCC or pull down to GND via a 100K
  • Leave them open
  • Enable the internal pull-ups (pin high, DDR as input)


Note that this is a low power application. It runs from a 3 volt lithium coin cell and is always asleep unless pin 7 (PB2, INT0) is pulled down with a pushbutton. Then it wakes up, does it's thing for about 150 msec, then goes back to sleep.


The AVR is set to fully asleep [ set_sleep_mode(SLEEP_MODE_PWR_DOWN); ]


I want to "handle" the unused pins in a manner that draws the least current (obviously).


Any advice will be appreciated.


Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Last Edited: Wed. Dec 5, 2018 - 05:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You have three choices for those unused pins:


1) Set them as outputs. Done.


2) Set them as inputs. Turn on internal pull-ups. Done.


3) Set them as inputs. Connect external pull-ups or pull-downs. Done, but why bother?


Note that NONE of the choices add to the power consumption unless something external is connected to those pins.


Why do you have external 100K pull-ups? Is it to "save" power? You don't. Just use the internal pull-ups, which are equivalent to about 25K to Vcc. If those are present to define the pin levels during boot and reset, then, yes, you do need something external. Otherwise, why bother?




Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Dec 5, 2018 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Krupski wrote:
to GND through a 100K resistor (this pin drives a BJT base through a 220 ohm resistor and I want that pin to be low when it's not being driven).
A BJT is not like a MOSFET.  You don't really need to pull down the base to keep the BJT off.  They are current-devices, not voltage devices.  But there isn't much harm either.  At 3V, a 100K resistor will sink 30 uA.


Bigger question is why use a BJT to begin with?  And why drive the base via a 220 ohm resistor?  The base current will be awfully high.  Take a typical 2N2222.  At Vcc=3V, and Vbe of 0.6V, your 220 ohm resistor will pass 11 mA.  Due to reduced pin driver strength at that Vcc, the I/O pin will likely sag to about 2.6V, for a current of about 9mA.  With an hFE of between 35 and 300 (depending on collector current and temperature), the collector current could be at least 300 mA.  Are you really driving that heavy a load from a coin cell?  In any event, your transistor is almost certainly well into saturation.  You can likely live with a much higher base resistor and lose less current into the BE junction.


So why not a MOSFET?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]


  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do some measurements yourself.

A convenient way to do this is to put a shunt resistor in series with Vcc or GND, and the place a scottky diode parallel to that resistor.

Dimension your shunt in such a way that it has enough of a voltage drop when the AVR sleeps, but not enough to significantly open the skottky diode ( Try around 100mV)

The skottky will limit the voltage drop when the AVR wakes up.


Also, put a 2 pin jumper in parallel with the resistor & diode.

It is an easy attachement for Dupont cables to your multimeter, and if there is andy doubt that these components influence some aspect of your uC then you can short it with a jumper.


For low power design you should always carefully analyse the whole circuit.

The idling current of a voltage regulator can easily swamp your uC sleep current.

Leaky elco's are also a common cause for prematurely depleted batteries.


The logic state of the I/O pins does not matter much for the current consumption.

The reason behind all this talk about logic levels is that if the voltage is somewhere halfway Vcc and GND, then both the N and P -channel MOSfets of the input can somewhat conduct. With some very old chips this can even be a few mA, but with more modern chips even this state is hardly noticable, but it can still add a noticable amount of battery drain.

So the goal is to keep the voltage levels on all pins outside of this region.


Just for fun, (& educational value) you can easily measure this by putting an un programmed AVR, (or to be sure: a simple program and define all pins as inputs) Then tie all pins together on a breadboard and connect them with a potentiometer. When the swiper of the poteniometer (and all the input pins) are near the middle, then you will find a measureable increase in current draw.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Fri. Dec 7, 2018 - 08:16 PM