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

AT89S8252 memory write and read problem

/*------------------------------------------------
Function for memory write
------------------------------------------------*/
void EeWrite()
	{
	temp_prog = PROG_NO - 0X30;
		WMCON |= EEMEN_;
    WMCON |= EEMWE_;
program[temp_prog].e_total_turns = prog.total_turns;
program[temp_prog].e_stop1_turns = prog.stop1_turns;
// same copying code here...

    for( i=0; i < 2500; i++ )
    {
       if( WMCON & EERDY_ )
           break;
    }

    WMCON &= ~EEMEN_;    // EEMEN=1;
    WMCON &= ~EEMWE_;    // EEMWE_=1;

	} 
This code I have written for writing an int ranging from 0000 to FFFF in the memory, but some problem is coming. Infact I have formed a structure in xdata memory and same type of structure in idata memory. I am trying to write the whole structure from idata to xdata. there are 5 of the same structures, so temp_prog is the pointer for a perticular structure. What could be wrong here. I read in the datasheet that you need to write eeprom byte by byte.
Now what should be my approach? beacuse if I will go for byte by byte write then the code size will be too big. (As there are 4 floats defined in the structure, 2 ints and 4 chars)
Even a single int = int is not working...
Is there any solution for this?
At power ON the same data I am reading back in the idata structure as follows.
/*------------------------------------------------
Function for memory read
------------------------------------------------*/
void EeRead()
{
temp_prog = PROG_NO - 0X30
WMCON |= EEMEN_;    // EEMEN=1;
prog.total_turns = program[temp_prog].e_total_turns;
prog.stop1_turns = program[temp_prog].e_stop1_turns;
prog.trvs = program[temp_prog].e_trvs;
prog.offset = program[temp_prog].e_offset;
prog.index = program[temp_prog].e_index;
prog.stop2_turns= program[temp_prog].e_stop2_turns;
prog.dir = program[temp_prog].e_dir;
WMCON &= ~EEMEN_;    // EEMEN=1;

	}

Will this reading code work. Because currently it is giving a garbage value.

This is one more observation that when I compile my code in Keil, it omits some of my Instructions

It sounds strange, but is true.
When after compiling I start debugging, it wont show the breakpoint at some positions. It won't execute that instruction too! While debugging a dark gray line appears in the program window.(Vertical) at few lines it becomes faint gray. During comments it is OK but I found them faint on few more places which are not comments.
I put the same command (example Pitch = 0X40;) below the above and then it compiles both of them and if I hide one of them, it won't compile a single.

Parents
  • "Now what should be my approach? beacuse if I will go for byte by byte write then the code size will be too big."

    Use a pointer in a loop to copy the structure(s) byte by byte. You need to map in the EEPROM, wait for the ready bit, write a byte, wait for the ready bit etc.

    To read, all you need to do is map in the EEPROM, wait for the ready bit then do a structure assignment.

    This is based on being familiar with a similar but not identical Atmel part so check the datasheet for precise information.

Reply
  • "Now what should be my approach? beacuse if I will go for byte by byte write then the code size will be too big."

    Use a pointer in a loop to copy the structure(s) byte by byte. You need to map in the EEPROM, wait for the ready bit, write a byte, wait for the ready bit etc.

    To read, all you need to do is map in the EEPROM, wait for the ready bit then do a structure assignment.

    This is based on being familiar with a similar but not identical Atmel part so check the datasheet for precise information.

Children
No data