This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with eeprom R/W

Hi
I want to read and write to the internal eeprom in the at89c51ed2. In simulation it seams OK, but in target, the volatile memory is allways read as 0xffh. I use the same routines for same processor in a different project without problems.
My test looks as follows:

IntTemp = 100;
eep_write(0,IntTemp);
i = eep_read(0);
if ( i !=IntTemp )
{
 error(1);
}

Can any of you help me?

My writing routine looks as follows:
void eep_write(byte address, int wdata)
{
bit	tmpEA = EA; //store EA state
 EA = 0;
 EECON = 0x02; // Enable EEPROM
 XWORD[address] = wdata;
 EECON = 0x50; //necessary for simulation to work, why?
 EECON = 0xa0; //same as above
 EECON &= ~0x02;
 EA = tmpEA;
 while(EECON & 1);
}
My reading routine looks as follows:
int eep_read(byte address)
{
bit tmpEA = EA;
int read_data;
 while(EECON & 1);
 EA = 0;
 EECON |= 2; // Map eeprom
 read_data = XWORD[address];
 EECON &= ~2; // Unmap eeprom
 EA = tmpEA;
 return(read_data);
}
Thanks!

Parents
  • " I use the same routines for same processor in a different project without problems."

    I can't see how that could be the case.

    Why don't you just do it exactly the way it is done in the datasheet flowcharts?

    You cannot write 16 bit values to the EEPROM as you have tried to do in your code. Write your functions using XBYTE and unsigned char to hold the value to be read/written.

Reply
  • " I use the same routines for same processor in a different project without problems."

    I can't see how that could be the case.

    Why don't you just do it exactly the way it is done in the datasheet flowcharts?

    You cannot write 16 bit values to the EEPROM as you have tried to do in your code. Write your functions using XBYTE and unsigned char to hold the value to be read/written.

Children