CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Mirror EEPROM to RAM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Orcino



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

Mirror EEPROM to RAM
PostPosted: Sun Nov 05, 2006 8:31 am     Reply with quote

Hi, the code:

teste = ee_read32(20);
buffer_coordenadas[10]=teste;

work, but in the loop not work , whi ? my buffer is static int32 buffer_coordenadas[200]. I am using the functions below, to write and to read eeprom.

void copia_eeprom_ram(void)
{

int16 cont;
int8 cont_buffer=0;
int32 var_temp;

for(cont=0; cont < 800 ; cont=cont+4)

{

var_temp = ee_read32(cont);
buffer_coordenadas[cont_buffer] = var_temp;
cont_buffer++;


}

}


//***********************************************************

void ee_write32(int16 base_address ,int32 data)

{

char i;
for(i=0; i<4; i++)
write_ext_eeprom(base_address+i,*(&data+i));

}


//***********************************************************


int32 ee_read32(int16 base_address)
{

char i;
int32 data_read;

for(i=0; i<4; i++)
*(&data_read+i) = read_ext_eeprom(base_address+i);
return (data_read);

}
Ttelmah
Guest







PostPosted: Sun Nov 05, 2006 9:06 am     Reply with quote

First comment. Use the code buttons to post code. It makes it vastly easier to read...
Code:

void copia_eeprom_ram(void) {
    int8 buffer_count;
    //Why fiddle around with two counters. Just use one...
    for (buffer_count=0; buffer_count < 200 ; buffer_count++) 
        buffer_coordenadas[buffer_count] = ee_read32(buffer_count);
}


//***************************************************
//Hand the address of the data, rather than having to copy it
//Also force the address to be to an int8, so it increments in bytes
void ee_write32(int16 base_address ,int8 *data) {
    char i;
    base_address*=4;
    for(i=0; i<4; i++)
       write_ext_eeprom(base_address+i,data++);
}

//***********************************************************
int32 ee_read32(int16 base_address) {
   char i;
   union {
       int8 b[4];
       int32 word;
   } data_read;
   base_address*=4;
   for(i=0; i<4; i++) {
      data_read.b[i] = read_ext_eeprom(base_address+i);
   return (data_read.word);
}

Now, I am modifying in a number of ways. The first is that I just use one counter, and handle scaling this in the read/write program. Since a multiplication by 4, is just done using a couple of shifts, this is quick, and removes the need to keep track of two different counter values.
The next, is instead of copying the physical data to the output routine, and then taking the address of this copy, I just hand the address of the original data to the routine. You will therefore need to call this, with:
ee_write32(buffer_count,&buffer_coordenadas[buffer_count]);

or the equivalent.
The third is to do with pointer handling (and applies to the second as well). In C, if you have a pointer to an int32, and increment it, it _should_ move to the next _int32_ (not the next byte inside it). CCS, has historically had this wrongly implemented, and incrementing a pointer normally moves by one byte. However on occassions, some versions of CCS, seem to start working as they should. Hence I am almost hellishly careful when dealing with pointer arithmetic, casting the pointer to an int8*, and incrementing by the size of the required type. In the second routine, I force the pointer arriving at the subroutine to be to an int8 (in the subroutine declaration), while in the third routine, I avoid the pointer maths, by using a union. I'd suspect that this may be why your code is giving problems.
Obviously, the test 'demo' you post, is wrong, since you are pulling the data from address 20, whereas this data should be coming from address 40 as posted in the loop.

Best Wishes
Orcino



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

Mirror EEPROM to RAM
PostPosted: Tue Nov 07, 2006 9:09 am     Reply with quote

Thanks Ttemah, but not work, you can show a small example ? I only need copy 200 var int32 form eeprom for buffer in memory RAM.

Thanks again


Orcino
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 07, 2006 9:39 am     Reply with quote

..

Last edited by treitmey on Tue Nov 07, 2006 10:24 am; edited 1 time in total
Ttelmah
Guest







PostPosted: Tue Nov 07, 2006 9:47 am     Reply with quote

It should work.
Just need something like:
Code:

   int8 address;
   int32 buffer[200];
   for (address=0;address<200;address++)
      buffer[address]=ee_read32((int16)address);

Remember that the data needs to be in the eeprom LSB first as written (you could obviously use a counter running the other way in the ee_read function, if you'd prefer the data the other way).
Are you sure you have the data correct in the EEPROM?. On your original 'working' demo, this would have required the data to be placed at half the address that it should be. The bytes for array[10], should start at eeprom[40], when you are pulling them from address 20.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group