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

Why do I get the MSB on eeprom corrupt?

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



Joined: 01 Oct 2003
Posts: 172
Location: Punta Gorda, Florida USA

View user's profile Send private message Send e-mail

Why do I get the MSB on eeprom corrupt?
PostPosted: Tue Apr 03, 2007 3:26 pm     Reply with quote

Hi there, Shocked

I seem to be having a problem with something that always worked in the past,(I am using V4.031 of CCS pcw) for some reason, I can't see why this does not work? Perhaps, I just can't see the problem that may be very obvious to others.

The problem is; I can read some value from a EEPROM location that I had placed a value, and the value contained in that location is correct and in the right order. However, when I write the same value to the same location I now get a new value, in other words, if I write the value of 950 (0x03B6) when I go to read or just look at was just written, it is now 438 (0x01B6) it looks like the higher byte is always set to 01?

Below are some excerpts of my code to illustrate what I'm saying

************************************************************************************************************

#ROM 0xF00010 = {950} // default value for current setpoint is 0x03B6 at location 16 of eeprom

#define EEPROMLEDBI 0x10 //location 16, 2 bytes for an int16

unsigned int16 nasty = 950;



ISetpoint = EERead(EEPROMLEDBI); // if we look at the value of variable ISetpoint after it is retrieved it is 950
// no problem reading eeprom


write_int16_eeprom(EEPROMLEDBI,nasty); // now we write variable "nasty" to eeprom and when the write is finished
// and we look at the contents of location 16 of eeprom we get 0x01B6 ????



Below are the eeprom read and write routines that I am using




int16 read_int16_eeprom(INT_EEPROM_ADDRESS address)
{
int8 i;
int16 data;

for(i = 0; i < 1; ++i)
{
*(&data + i) = read_eeprom(address + i);
}

return(data);
}



void write_int16_eeprom(INT_EEPROM_ADDRESS address, int16 data)
{
int8 i;

for(i = 0; i < 2; ++i)
{
write_eeprom(address + i, *(&data + i));

}

}
***************************************************************************************************************
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Apr 03, 2007 4:09 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=30062
See Ttelmah's first post.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 03, 2007 4:13 pm     Reply with quote

More info:
http://www.ccsinfo.com/forum/viewtopic.php?t=29735

Also see the updated source code in the CCS FAQ:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte
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