struct's in EEPROM, wtf?

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

I want to put configuration data in the EEPROM of an ATmega8. I also want to do checksum calculations on the data. I declare a struct and a variable of that type:

typedef struct 
{
	uint8_t		LENGTH;
	int32_t		_SERVO_POS;
	int32_t		_SERVO_CENTER;
	int32_t		_SERVO_SPAN;
	uint16_t	_RC_CENTER;
	uint16_t	_RC_SPAN;
	uint8_t		_SERVO_PGAIN;
	uint8_t		_SERVO_DGAIN;
	uint8_t		_MOTOR_CURRENT_CAL;
	uint8_t		_MOTOR_CURRENT_MAX;
	uint16_t	_MOTOR_FREQ_MAX;
	uint8_t		_MOTOR_TEMP_MAX;
	uint8_t		_FET_TEMP_MAX;
	uint8_t		_CHECKSUM;
} configdata_t;

// EEPROM configuration data
volatile	configdata_t	eeconfigdata	__attribute__((section(".eeprom")));

So then I just want to check comiling is OK, so I initialize with this:

	volatile configdata_t *dpointer;
	dpointer			= &eeconfigdata;
	if (dpointer == 0)
		PORTB = 0;

but this compiles into

	dpointer			= &eeconfigdata;
	if (dpointer == 0)
		PORTB = 0;

	SERVO_NEUTRAL		= SERVO_POS;		// Neutral position = current position
  aa:	80 91 9a 00 	lds	r24, 0x009A
  ae:	90 91 9b 00 	lds	r25, 0x009B

i.e. absolutely nothing.

I just added the PORTB stuff to make sure compiler doesn't ignore the pointer which isn't used anywhere...
There are no warnings or errors from GCC, but still it doesn't produce any code for the pointer assignment. Anyone knows what's wrong?

/Jakob Selbing

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

Declaring a varible in the EEPROM section only places it in a new section of blank memory addresses, so that each variable has a unique address that is not influenced by RAM. You still need to use the GCC read block and read byte EEPROM commands, but pass your EEPROM section variable pointers as the read address.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

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

I know that EEPROM cannot be accessed using standard C. In this case I simply want the EEPROM address of the variable (so that I can use it for EEPROM read/write), but even that doesn't work.

/Jakob Selbing

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

Perhaps because the struct's starting at EEPROM location 0, the pointer compare against 0 is being optimised out?

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!