Attiny45 deepsleep and I2C

Hi All

I have a attiny45 running @1Mhz internal clock, set to deepsleep and wake with a button press. When sleeping, consumption goes down to 0,3uA.

Later i add a I2C sensor with 4,7K pullups on I2C lines and now when sleeping, consumption goes to 1,7mA.
I thought the culprit was the I2C sensor, so i removed it, but it didn't change consumption. So i removed SCK pullup and i get 0,4uA. Removing SDA pullup i got the original 0,3uA.

So, is there any way to prevent I2C pullups (major SCK) from drawing those extra 1,7mA? Bellow is my sleep code:

void goToSleep () {
  
  cbi(ADCSRA,ADEN);                       // switch Analog to Digital converter OFF
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
  sleep_enable();
  sleep_mode();
  // sleep here - wake by Interrupt
  sleep_disable();
  sbi(ADCSRA,ADEN);                     // switch Analog to Digital converter ON
}

Thanks

Try set to Hi-Z(aka INPUT) on used pins before entering to sleep.

I don't know what library you are using, but presumably you enable I2C with something like wire.begin(), which turns on the USI peripheral in the 85. That will also cause the peripheral to take over the two GPIO pins to be used as SDA and SCL. But your library may not have a wire.end() function which would undo all of that. If it doesn't, you might try writing zero to the USICR register, which turns off the peripheral and releases the GPIO pins. You may also then have to set those pins to INPUT, but turning off the peripheral may automatically leave them that way. Then when you come back from sleep, you'll need to start over on I2C with another wire.begin() call. I've never actually tried this, but the datasheet for the 85 suggests it would work.

Thanks @chrisknightley and @ShermanP, i'll try your suggestions.
I'm using TinyWireM, it was the only library i could put to work with attiny

geologic:
Thanks @chrisknightley and @ShermanP, i'll try your suggestions.
I'm using TinyWireM, it was the only library i could put to work with attiny

It seems that the function corresponding to Wire.end() is not implemented in the TinyWireM library.

Try adding the following two codes before sleep_enable().

DDRB  = 0x00; // all PORTB set to INPUT
USICR = 0x00; // USI(I2C) Disable

As ShermanP says, you'll have to do Wire.begin() again when you wake up from sleep.
In addition, if you are using a GPIO other than I2C, you will need to set pinMode() again.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.