cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
Why do I get the MSB on eeprom corrupt? |
Posted: Tue Apr 03, 2007 3:26 pm |
|
|
Hi there,
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));
}
}
*************************************************************************************************************** |
|