Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: need variables to be stored in EEPROM

2005-04-26 by arhodes19044

This makes sense.  Did you truncate off the high bits down to (2048-
1)because the CPU you were using had only 2k bytes of EERPROM?  
Since the 128 has 4K, I guess then the address would be truncated to 
(4096-1)?

-Tony

--- In AVR-Chat@yahoogroups.com, David Kelly <dkelly@h...> wrote:
> On Tue, Apr 26, 2005 at 03:33:07PM -0000, arhodes19044 wrote:
> > 
> > OOOOPS.  That last part, 4 clock cyles, is pretty critical 
timing.  
> > I COULD disable interrupts for just step 4 and 5.
> > 
> > I can modify the code for the  Libc eeprom code to suit that.  
This 
> > is a very brief suspension. of the interrupts.
> 
> I haven't looked at the avr-libc version but wrote my own, it 
ain't that
> hard. However this code hasn't been tested yet:
> 
> //
> //	write to EEPROM
> //		addr is the address within the EEPROM
> //		cp is where to read data in RAM
> //		n is the number of 8 bit octets to copy
> //
> void
> ee_writes(uint16_t addr, void *cp, uint8_t n)
> {
> 	for( ; n ; n-- ) {
> 		wdt_reset();
> 		while( EECR & (1<<EEWE) )	//  wait until ready
> 			;
> 		
> 		EEAR = addr & (2048-1);	//  stripped to 11 bits, 2kB
> 		EEDR = *((uint8_t*)(cp)++);	//  looks frightening
> 		addr++;
> 	
> 		cli();			//  an IRQ would ruin this 
timing
> 		EECR |= (1<<EEMWE);	//  only stays set for 4 
clocks
> 		EECR |= (1<<EEWE);	//  hit EEWE before EEMWE 
clears
> 		sei();			//  assume IRQ was enabled
> 	}
> }
> 
> -- 
> David Kelly N4HHE, dkelly@H...
> 
=====================================================================
===
> Whom computers would destroy, they must first drive mad.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.