I would like to wake Attiny45 from sleep by Serial communication. RX is connected to pin 7 (D2). When I try to use PCINT0_vect routine, I get an error "multiple definition of `__vector_2'" so it looks like Software Serial already uses "ISR (PCINT0_vect)" and pin change interrupt.

So my question is, will incomming communication wake Attiny from sleep?

Is there a possibility to change CLKPR when Attiny starts receiving? For example I set clock divider to 256 for the majority of time and when it starts receiving it changes back to 1.

I was thinking of something like this:

void loop() {
 if (SWSerial.available()>0) {
   noInterrupts ();
   CLKPR = bit (CLKPCE);
   CLKPR = clock_div_1;
   interrupts ();
//other code here

I don't mind loosing some bytes, but I need to low Idle current as much as possible. Thank you.

  • Have you tried it? What were your results?
    – Majenko
    Jul 2, 2015 at 11:11
  • Any reason why you don't use the USI on pin 5 to read your serial data? Hardware support for reading in the bits and also ability to wake when a start condition is detected.
    – bigjosh
    Jul 2, 2015 at 14:01
  • I haven't received my attiny yet. I didn't know there is such possibility, I have pin 5 unconnected. But I can modify it.
    – lakotamm
    Jul 3, 2015 at 11:47

1 Answer 1


Question #1: Can a change on pin 7 wake from sleep?

Yes. The lowest power mode for this chip is Power-down, and you can wake from this state with a pin change interrupt. Assuming that the soft-serial code you are using already enables interrupts on the pin for its own purposes, then you should just be able to sleep and the part will wake on the next pin generated interrupt.

Depending on what compiler/libraries you are using, something like this...

include <avr/sleep.h>


//We will only reach this line after an interrupt has occured

...should work. Note that an interrupt when waking from sleep takes longer than when already running, so you'll need to check your soft serial library to see if it will possibly garble the first bit received- it will depend on how they do their timing.

If you really want the lowest power possible, you could write your own soft serial code that drops the processor to idle in between serial bit transitions. Depending on how much time you will be spending actually receiving data this could drop overall power consumption dramatically.

For low baud rates, I could imagine writing serial receive code that woke on an interrupt from the start bit, and used the timer running at a very low clock speed to wake up in the middle of each data bit and very quickly sample and shift the bit in before going idle again. Done right, this could dramatically drop the power used while receiving.

Question #2: Is there a possibility to change CLKPR when Attiny starts receiving?

Yes. You can change the prescaler any time, but note that...

  1. The clock is not running at all during power-down mode, so there is no reason to scale back before going to sleep - it will just mean that it takes you longer to wake up when a change happens.

  2. Sometimes scaling back the clock can actually use more power, especially when sleeping is envolved. A processor running 1/2 as fast uses more than 1/2 as much power, so it is often more power efficient to wake up at full speed, do what you have to do as fast as possible, and then get back to sleep.

The best option for you will depend on factors like how often will you be receiving data compared to waiting for data, and how much work you wan to put into getting optimal power usage. This chip can be extremely power efficient, but it can take work to take advantage of it.

  • I don't need low power consumption during communication.
    – lakotamm
    Jul 3, 2015 at 11:53
  • Chip will be conncted to 20Ah battery and it will comunicate only during charging. I haven't decided whether I will use power down or only slow down the chip. Thank you for your answer. :-)
    – lakotamm
    Jul 3, 2015 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.