Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

simple C question (ICC AVR related)

Status
Not open for further replies.

nachus001

Junior Member level 2
Joined
Sep 8, 2003
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
238
iccavr initializer must be constant

Hi all:

My questions is on how to retrieve an address from an item stored in eeprom.
I´m currently using the ICC AVR which works very well, but I have some errors trying do whith this example:

//chipset AT90S2313
.
.
.
.

#pragma data: eeprom // switch to eeprom area and reserve some data
//space

char foo[20]; //array 1
char man[10]; //array 2
char bar[5]; //array 3

#pragma data:data // switch back to SRAM

.
.
.

const char sizes_ee[] = {sizeof foo, sizeof man, sizeof bar}; //const table
// with the sizes of data

// here comes the problems when trying to retrieve addresses
const char bases_ee[] = {&foo[0], &man[0], &bar[0]};


Well, the compiler complains all sort of things(mainly "initializer must be constant") when compiling this last line. I´dont know how to fix this.
I know "&" is a run time direction operator, but I´ve seen that it can be interpreted as a "compiling time" operator (assigning the correct data to a const array, in this case)

Can anyone here help me?
Modifications and casts like

const char bases_ee[] = {(char)&foo[0], (char)&man[0], (char)&bar[0]};

make things worse (the compiler complains harder)


Thxs in advance
Nachus
 

iccavr access to specific memory address

Try to use char* bases_ee[] as you are trying to init pointer structure , but I am not sure that those will be be correct . Pointers to char are about RAM location but EEPROM story is different . There is certain differentiation between EEPROM and RAM . The EEPROM access via single pointer must be allowed within compiler to make it transparent for you (C single pointer manipulation must be explored as macro into memory access routine call) . If it is not implemented in ICC you must have use wrappers for EEPROM access as
putEstring (char* tstring, int Eadr); // tstring is about pointer to RAM where
// strng to be written into EEPROM is
// stored.
// Eadr is starting address to EEPROM
// where string will be stored

getEString(char* tstring, int Eadr);// tstring is the pointer to valid memory
// in RAM no less than string you re
// going to read from EEPROM
// Eadr is the starting pointer to EEPROM
// location where your string previously
// has been stored

Read how to access EEPROM in Atmel AN DOC0932.pdf and asm source file AVR100.asm "Accessing AVR EEPROM" . This will guide how to write read into eeprom .(www.atmel.com)
 

eeprom_read icc

artem is correct.

you declare an array of char (1 byte) and you try to initialize each char with pointers to char (2 bytes). This obviously wont work ;-).

Don't forget to use the wrapperfunctions icc provides to access the eeprom! You cannot use the datastructures in the same way as the ones in ram.

btw: You should get something like this (I haven't tested whether it works!!!):
EEPROM_READ( (int)&((bases_ee[1])[3]), number) would be a construct which reads the value to the forth byte of 'man' into number.

bases_ee[1] gets the pointer to the base adress of 'man'
(bases_ee[1])[3] is the 4th value from 'man'
and &((bases_ee[1])[3]) gives the adress of the 4th value of man.
since the eeprom is accessed with position (integer) and not with a pointer, the pointer is casted to an integer.

Antharax
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top