Author Topic: AVR EEPROM programming  (Read 2656 times)

bioroids

AVR EEPROM programming
« on: December 13, 2007, 02:13:03 PM »
Hi guys!

I'm following the procedure that is in the datasheet, but the bytes don't seem to stuck to the EEPROM  :icon_evil:

What do you think of this:

// Write to EEPROM
EEDR = 1;            // Data to be written
EEAR = 0x7F;         // Address to be written to
EECR |= 0x01 << EEMWE;   // Enable Master Write
EECR |= 0x01 << EEWE;   // Do write
while (EECR & (0x01<<EEWE)) {
    // Wait for write to complete
}


By the way, this is an ATTiny26. It's driving me mad! Still working on the PWM Phaser, and the ATTiny13 was too small for it
   
Any help is greatly appreciated

Miguel
Eramos tan pobres!

The Tone God

Re: AVR EEPROM programming
« Reply #1 on: December 13, 2007, 02:17:26 PM »
Give me a few and I'll compare what you have to my EEPROM library.

Andrew

bioroids

Re: AVR EEPROM programming
« Reply #2 on: December 14, 2007, 06:42:56 AM »
Problem solved!

It turns out that I wasn't using optimization, so the code I posted above, when compiled, required more than 4 cycles, and that is restriction for the write to be executed. The optimization solved that (and also reduced my code from 2046 bytes to about 1600 :icon_exclaim:).

Just for the record, I also had to declare some global variables as volatile, because the optimizer loaded them in registers and when the value was changed outside the main function, the change was lost.

Everything is back on track! Thanks Tone God for introducing me to this little and powerfull monsters

Regards

Miguel
Eramos tan pobres!