Using EEMEM in a class

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Studio 7

 

In the class include file I have the following declaration

 

uint8_t EEMEM NonVolatileString[16][18];

 

This fails to make with the following errors

 

expected ';' at end of member declaration    

 'NonVolatileString' does not name a type

 'Section atribute not allowed for 'NonVolatileString'

 

I'm not knowledgeable enough to figure out what's wrong or if I simply can't do this so any help would be appcreciated

 

Regards

 

This topic has a solution.

 

 

Last Edited: Tue. Jul 9, 2019 - 02:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe not your problem, but you don't say which AVR. Many have EEMEM sizes that are 256 bytes or less. Your declaration uses 288.

 

You might check about how much space your device actually has.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Sorry my bad, target is a 328P so 1024 available

 

regards

 

 

 

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

Apply the attribute at the point of instantiation not declaration.

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

clawson wrote:
Apply the attribute at the point of instantiation not declaration.

Like this, as an example:


#include <avr/io.h>
#include <avr/eeprom.h>

class EEPROM {
	private:
		static char strings[][18];

};

EEMEM char EEPROM::strings[][18] = {
	"Test"
};

int main(void) {
    while (1) {
    }
}

I assume you want them static so that you can initialize the strings statically... If not, then you need read/write functions from the avr/eeprom.h file...

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

Thanks,

 

It compiles but I don't seem to be able to set any values.  It seems to be an offset, but I'm not sure.  When I try the following within the class

 

//instantiate a copy of myclass

myclass  test;

 

myclass.h

private:

    static uint8_t NonVolatileString2[5];

 

in main.cpp

EEMEM uint8_t test::NonVolatileString2[] ;

 

in class

eeprom_write_byte(&NonVolatileString2,0x21); 

 

 

-----------------

Error  cannot convert 'uint8_t (*)[5] {aka unsigned char (*)[5]}' to 'uint8_t* {aka unsigned char*}' for argument '1' to 'void eeprom_write_byte(uint8_t*, uint8_t)'

 

Am I simply just missing something?  I basically want to read/write to the eeprom from within a class, populating data to be wrtten from within the class

 

regards

 

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now you're just mixing types...

 

uint8_t NonVolatileString2[5] is a pointer to the first element of a array of 5 uint8_t things.

 

Writing the first byte will then be  eeprom_write_byte(&NonVolatileString2[0],0x21), writing the second byte is eeprom_write_byte(&NonVolatileString2[1],0x21) etc...

 

Or, if you want to write blocks, use eeprom_write_block.

 

PS; use the _update_ functions instead of read/write. The _update_ functions will check if the value actually has to be written, possibly saving a write cycle of the eeprom.

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

Perfect!  Thanks for the pointers (no pun intended smiley )

 

regards