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
  • As the datasheet said , when read and write eeprom, the program must check the EEBUSY to make sure the EEPROM can make the reply.(also need to disable EA if your int routin use the RAM address covered by EEPROM at that time )
    Please reffer the keil's sample:
    ...Keil\C51\EXAMPLES\FarMemory, they are some sample code in A51 file and you must notice it is for T89C51RD2
    and more, the file "Mifration from T89C51RD2 to AT89C51RD2/ED2" from ATMEL can make you know how to modify the A51 file for ED2


    Hope these can help all the guys. This above words cost me nearly 40 hours continous work... :(


    BR
    Zona

Reply
  • As the datasheet said , when read and write eeprom, the program must check the EEBUSY to make sure the EEPROM can make the reply.(also need to disable EA if your int routin use the RAM address covered by EEPROM at that time )
    Please reffer the keil's sample:
    ...Keil\C51\EXAMPLES\FarMemory, they are some sample code in A51 file and you must notice it is for T89C51RD2
    and more, the file "Mifration from T89C51RD2 to AT89C51RD2/ED2" from ATMEL can make you know how to modify the A51 file for ED2


    Hope these can help all the guys. This above words cost me nearly 40 hours continous work... :(


    BR
    Zona

Children
  • Sorry for mistype and the file name is "Migration from T89C51RD2 to AT89C51RD2/ED2"
    the link:
    http://www.atmel.com/dyn/resources/prod_documents/doc4239.pdf


    I am too tired....:(

  • Well, after all I have the way:

    unsigned char __api_rd_eeprom_byte(unsigned int adr)
    {
    unsigned char val;
    bit ea_save;
    while (EECON&1)
    {WDT_feed; //Watch dog,this "while" many be few mS when you W/R continously
    };//Eeprom_busy()
    ea_save=EA;
    EA=0;
    EECON |= 0x02;//Enable eeprom data;
    val=*(unsigned char xdata*)adr;
    EECON &= ~0x02;//Disable eeprom data;
    EA=ea_save;
    return val;
    }


    void __api_wr_eeprom_byte(unsigned int adr, unsigned char value)
    {
    bit ea_save;
    while(EECON & 0x01)
    {WDT_feed; //Watch dog,this "while" many be few mS when you W/R continously
    };// wait bit busy
    ea_save=EA;
    EA=0;
    EECON |= 0x02;//Enable eeprom data
    *(unsigned char xdata*)adr=value;
    EECON &= ~0x02;//Disable eeprom data
    EA=ea_save;
    }

    the api only support 1B's R/W, so you should do the managment of WORD/DWORD type's Read/Wrote...


    Michael Christensen 's problem is because his routine is for T89C51ED2, not AT89C51ED2, Atmel has a pdf told you the difference between these 2chip... and the routine in this post is for AT89C51ED2... Hope it can help the newer...