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

read/write int32 on internal EEPROM

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



Joined: 29 May 2004
Posts: 41
Location: Barcelona, Spain

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

read/write int32 on internal EEPROM
PostPosted: Wed Sep 23, 2009 9:39 am     Reply with quote

Hi all,

i'm trying to store 32bit data on internal eeprom and after to recover it .

Functions I'm using.

Code:
CCS Compiler version: 4.023


For write:

Code:
void write_float_eeprom(int32 n, int32 data)
{
   int i;

   for (i = 0; i < 4; i++)
   {
      write_eeprom(i + n, *((int *)&data + i) ) ;
   }
}


For read:
Code:
float read_float_eeprom(int32 int n)
{
   int i;
   int32 data;

   for (i = 0; i < 4; i++)
   {
      *((int *)&data + i) = read_eeprom(i + n);
   }
   return(data);
}


Code:
Code:
void read_EEPROM_setup ()
{
   write_float_eeprom (0x00000000, 0x1234567F);
   printf ("\fData stored in EEPROM\r\n");
   delay_ms (500);
   printf ("Data EEPROM Read\r\n");
   data_32bits = read_float_eeprom (0x00000000);
   printf ("32bit data: 0x%8LX\r\n", data_32bits);
   printf ("[0]: 0x%X\r\n", read_eeprom (0x00));
   printf ("[1]: 0x%X\r\n", read_eeprom (0x01));;                                               
   printf ("[2]: 0x%X\r\n", read_eeprom (0x02));
   printf ("[3]: 0x%X\r\n", read_eeprom (0x03));
   delay_ms (5000);
}


Results:
Code:
Data stored in EEPROM
Data EEPROM Read
32bit data: 0x0000007F
[0]: 0x7F
[1]: 0x56
[2]: 0x34
[3]: 0x12


So this function:
Code:
data_32bits = read_float_eeprom (0x00000000);


seems to not work. Anybody has this problem ?. I'd tested previous post but with no luck.

Regards,

Joan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 23, 2009 11:24 am     Reply with quote

Quote:

I'm trying to store 32bit data on internal eeprom and after to recover it.

I assume this means you want to read and write an 'int32' to eeprom.

Read your code with a critical eye:
Quote:

float read_float_eeprom(int32 int n)
{
int i;
int32 data;

for (i = 0; i < 4; i++)
{
*((int *)&data + i) = read_eeprom(i + n);
}
return(data);
}

1. What is wrong with the function parameters ?
What is your intention, and what do actually have in the code above ?

2. What is wrong with the return value data type ?
What data type do you intend to return, and what type have you
told the function to return ?

3. Also, just as a cosmetic issue, you want to read and write an 'int32'
to the eeprom. What is wrong with the names you have given to the
functions ? What should the names of the functions be, if you want to
give them accurate names ?
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