Hello!
I've got a small battery powered circuit running from a 32Khz crystal which may log events about every hour by writing to EEPROM.
Since the batteries are very small I've tried to keep current consumption very low. The circuit runs full tilt on just 13µA @ ~ 4.5 volts with CLKPR=2 (8Khz clock). This is fine.
However, after having written a single byte to EEPROM the current jumps to 80µA and stays there. I've even tried reproducing the datasheet's EEPROM writing function to eliminate avr-lib as a suspect but the behaviour remains the same.
Nothing I tried so far reduces the current back to its initial value; once EEPROM is written, only a strobe on RESET fixes it, but I'd rather avoid that.
Both searches here and my google-fu failed me.
I've reduced the test case to a small program that illustrates the problem. The following code basically turns off µC features, sets up a 1 interrupt per second ISR and then the main loop waits until ten seconds have passed and then writes a byte. 13µA on power up, 10 seconds later constant 80µA.
#include#include #include #include volatile uint8_t sentinel=0; ISR(TIM1_COMPA_vect) { sentinel++; } void eewritebyte(uint16_t address, uint8_t byte) { while(EECR&(1<<EEPE)); EECR=0; EEAR=address; EEDR=byte; EECR|=(1<<EEMPE); EECR|=(1<<EEPE); } void inithardware(void) { CLKPR=(1<<CLKPCE); CLKPR=2; // 8Khz. DDRA=0; PORTA=0xff; // All pull-ups to prevent floating inputs. DDRB=0; PORTB=0xff; // All pull-ups to prevent floating inputs. PRR|=(1<<PRTIM0); // Turn timer0 off. PRR|=(1<<PRADC); // Turn ADC off. PRR|=PRUSI; // Turn USI off. ACSR|=(1<<ACD); // Turn off Analog comparator. TCCR1B|=(1<<WGM12)|(1<<CS10); // CLKio, CTC TIMSK1|=(1<<OCIE1A); // Enable COMPA interrupt. OCR1A=8191; // ISR @ 1Hz. sei(); } int main(void) { uint8_t barbar=0; uint8_t oldsentinel=0; inithardware(); while(1) { if(oldsentinel!=sentinel) { if(sentinel==10) { sentinel=0; cli(); // eeprom_write_byte((uint8_t *)10,barbar++); // lib-avr. eewritebyte(10,barbar++); // datasheet. sei(); } oldsentinel=sentinel; } } }
The date code on the ATTINY84A-PU is 1127 (Not sure if that's a factor.)
Anyone have ideas?