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

Go To Last Post
359 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

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

 

  • 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

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

I know it's been a long time since you posted this, but is there such library for the Arduino.

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

I know it's been a long time since you posted this, but is there such library for the Arduino.

Cant you access EEAR, EEDAR, & EECR??...if you can you can easily get the value you need from EEPROM or store it...what more would you need to do?   That assumes you have a specific location you wish to access.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sun. Apr 25, 2021 - 07:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fifi5675 wrote:

I know it's been a long time since you posted this, but is there such library for the Arduino.

 

The EEPROM.h library is part of the standard Arduino distribution (and 3rd party cores) for those MCUs that have on-chip EEPROM, which include the common AVRs. Other MCUs, e.g. Arm, that don't have on-chip EEPROM may offer an emulation library using flash.

 

EEPROM is usually presented as an array, e.g. EEPROM[42] = 7; you can also write this as EEPROM.write(42, 7);

Pages