[TUT] [C] Using the EEPROM memory in AVR-GCC

Go To Last Post
356 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks you for helpingyes

...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Every Atmel Datasheet I've seen has code examples on how to access the EEPROM similar to this:

Containing a wait loop looking at the EEPROM busy bit.  No external delay needed.  How did you miss that?

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I've followed the tutorial through and had some success. I'm trying to use the eeprom for counters so I know how often and on what mode the product is used and so at a point I want to increment one in an array of counters.

I tried to follow through on the example code but convert it to uint16_t array. Some save, some don't. Is my eeprom update block statement correct? Can I even do this?

Thanks in advance,

 

#include

uint16_t  EEMEM NonVolatileString[10];

int main(void)
{

	uint16_t  SRAMstring[10];

	eeprom_read_block((void*)&SRAMstring, (const void*)&NonVolatileString, 10);
	SRAMstring[1]++;
	eeprom_update_block((const void*)SRAMstring,(void*) NonVolatileString,10);
}

 

markah

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
eeprom_read_block((void*)&SRAMstring, (const void*)&NonVolatileString, 10);

10 bytes is not the length of a 10 element array of 16bit values. The size is actually 20 bytes (10 lots of 2 bytes). Of course you could just use:

eeprom_read_block((void*)&SRAMstring, (const void*)&NonVolatileString, sizeof(SRAMstring));

This way if you value the [10] dimension the number of bytes read/written will vary.

markah wrote:
Some save, some don't.
Well "some" means the first 5 save and the second 5 don't.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doh!

Not the first time you have come to my rescue! Much appreciated

Mark

markah

Pages