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 support@ccsinfo.com

int32 and eeprom

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







int32 and eeprom
PostPosted: Wed Oct 23, 2002 12:51 pm     Reply with quote

How Can I write a int32 variable to the internal eeprom ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 8123
Nicholas Kinnas
Guest







Re: int32 and eeprom
PostPosted: Wed Oct 23, 2002 1:14 pm     Reply with quote

<font face="Courier New" size=-1>:=How Can I write a int32 variable to the internal eeprom ?

to restore

v1 = read_eeprom(address);
v2 = read_eeprom(address+1);
v3 = read_eeprom(address+2);
v4 = read_eeprom(address+3);

i32 = Make32(v1,v2,v3,v4);</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 8126
Nicholas Kinnas
Guest







Re: int32 and eeprom
PostPosted: Wed Oct 23, 2002 1:18 pm     Reply with quote

:=How Can I write a int32 variable to the internal eeprom ?

write_eeprom(address,make8(var,0))
write_eeprom(address+1,make8(var,1))
write_eeprom(address+2,make8(var,2))
write_eeprom(address+3,make8(var,3))
___________________________
This message was ported from CCS's old forum
Original Post ID: 8127
johnpcunningham
Guest







Re: int32 and eeprom
PostPosted: Wed Oct 23, 2002 2:18 pm     Reply with quote

:=How Can I write a int32 variable to the internal eeprom ?

Here is one that I have used and works well
////////////////////////////
void ee_write32(char base_address ,int32 data){
char i;
for(i=0; i<4; i++)
write_eeprom(base_address+i,*(&data+i));
}
////////////////////////////

////////////////////////////
int32 ee_read32(char base_address){
char i;
int32 data_read;

for(i=0; i<4; i++)
*(&data_read+i) = read_eeprom(base_address+i);
return (data_read);
}
/////////////////////////////

////////////////////////////
void main(){
int32 data, data1;

data = 0xA5A5A5A5;
ee_write32(0x00, data); //write data to EEPROM loc 0x00

data1 = 0x12345678;
ee_write32(0x04, data1); //write data to EEPROM loc 0x04

data = ee_read32(0x00); //read data from EEPROM loc 0x00
data1 = ee_read32(0x04); //read data from EEPROM loc 0x04
while(1){}; //infinite loop
}
////////////////////////////
___________________________
This message was ported from CCS's old forum
Original Post ID: 8130
R.J.Hamlett
Guest







Re: int32 and eeprom
PostPosted: Wed Oct 23, 2002 2:52 pm     Reply with quote

:=How Can I write a int32 variable to the internal eeprom ?

As a slightly more 'generic' answer than those allready given:
void EEPROM_GET(int *ptr,int num,int addr)
{
int count;
for (count=0;count {
INTOFF;
*ptr++=RD_EEPROM(addr+count);
INTON;
}
}

void EEPROM_PUT(int *ptr,int num,int addr)
{
int count;
for (count=0;count {
INTOFF;
WRT_EEPROM(addr+count,*ptr++);
INTON;
}
}

Now I use the macros 'INTON', and 'INTOFF', to enable/disable any interrupts that might also use the same data areas that are being transferred to the EEPROM/from the EEPROM. So (for instance) if you are storing a value that is also used in a clock, then you should disable the clock interrupt during transfers.
The routines are called with the address of the variable to be transferred, the number of bytes to transfer, and the address in the EEPROM.
So to write a int32 to the start of the EEPROM (address 0 in the EEPROM), you would use:

EEPROM_PUT(&int32variable,sizeof(int32variable),0);

while getting it back from the EEPROM would use:

EEPROM_GET(&int32variable,sizeof(int32variable),0);

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 8132
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