Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Re: need variables to be stored in EEPROM

2005-04-26 by David Kelly

On Tue, Apr 26, 2005 at 06:10:12PM -0000, arhodes19044 wrote:
> 
> OK, I like this technique because _I_ do not have to keep track of 
> the address of variables in EEPROM.  But....
> 
> Always a but.  How do I use this command.  I tried it in the C 
> source inside main().  This gave errors.  
> 
> I then put it into the makefile, and I got no errors, but who knows 
> what it did with the command.  When I referenced the variable, I got 
> an "undeclared" error.
> 
> So, where I I put the command you suggest, and then how do I use the 
> resulting variable?

I don't quite follow your problem. Does this answer your question?

#include <avr/eeprom.h>

typedef struct {
	int	a,
		b,
		c;
	char	s[32];
} EEDATA;

EEDATA eedata __attribute__ ((section (".eeprom")));
EEDATA data;

void
main()
{
	while(1) {
		data.a = 0;
		eeprom_read_block( &data, &eedata, sizeof(data) );
		
		data.a++;
		eeprom_write_block( &data, &eedata, sizeof(data) );
	}
}

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
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.