Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/10/10 17:16
Modified:
  04/10/10 17:16

Read: times


 
#174963 - EEPROM Read/Write Issues
First of all, Terribly sorry for double posting, but I accidentally posted my thread on the wrong forum.

Now, for the issue at hand, I am having problems reading the EEPROM in my project.

I am using an Atmel 89c5131 MCU with a built in 1K EERPM/RAM both Addressed between 0x0000 and 0x03FF (with a bit in the EECON SFR to distinguish them). however whenever I call the read function the program seems to freeze.

I read the Datasheet, and it said this:

Write Data in the Column
Latches
Data is written by byte to the column latches as for an external RAM memory. Out of the
11 address bits of the data pointer, the 4 MSBs are used for page selection (row) and 7
are used for byte selection. Between two EEPROM programming sessions, all the
addresses in the column latches must stay on the same page, meaning that the 4 MSB
must not be changed.
The following procedure is used to write to the column latches:
• Set bit EEE of EECON register
• Load DPTR with the address to write
• Store A register with the data to be written
• Execute a MOVX @DPTR, A
• If needed, loop the three last instructions until the end of a 128 bytes page

Programming The EEPROM programming consists on the following actions:
• Writing one or more bytes of one page in the column latches. Normally, all bytes
must belong to the same page; if not, the first page address will be latched and the
others discarded.
• Launching programming by writing the control sequence (54h followed by A4h) to
the EECON register.
• EEBUSY flag in EECON is then set by hardware to indicate that programming is in
progress and that the EEPROM segment is not available for reading.
• The end of programming is indicated by a hardware clear of the EEBUSY flag.

Read Data The following procedure is used to read the data stored in the EEPROM memory:
• Set bit EEE of EECON register
• Stretch the MOVX to accommodate the slow access time of the column latch (Set bit
M0 of AUXR register)
• Load DPTR with the address to read
• Execute a MOVX A, @DPTR


so based on it, I made these 3 subroutines:

void EEPROM_Normal()
{
EECON=0x00;	//Allow usage of EPROM
AUXR=0x0C;	//Restore normal R/W Cycles						  
}

void EEPROM_Write()
{
EECON=0x54;	//Programming
EECON=0xA4;	//Sequence
Delay(5);		//Delay to give the EEBUSY time to rise
while((EECON==0xA5)|(EECON==0x01));		//Wait till EEBUSY is off					 
EEPROM_Normal();	//Restore normal situation
}

void EEPROM_Read()
{
EECON=0x02;	//Access EPROM
AUXR=0x2C;	//Extend the Read cycles to accomidate for slow memory
}

 

with EEPROM_Read() being called right before actions regarding Reading For example:
unsigned char xdata test[10] _at_ 0x000

void main()
{
unsigned char data[10],i;
EEPROM_Read();
for(i=0;i<10;i++)
data[i]=test[i];
EEPROM_Normal();
}
 

EEPROM_Write() being called right after modifying a variable, for example:
unsigned char xdata test[10] _at_ 0x000

void main()
{
unsigned char data={0,1,2,3,4,5,6,7,8,9},i;
EEPROM_Normal();
for(i=0;i<10;i++)
test[i]=data[i];
EEPROM_Write();
}

 

and EEPROM_Normal() after any reading session(and at the end of the writing routine) and resets the AUXR SFR for normal real cycles.

what am I doing wrong?

Heres a copy of the Datasheet:

http://www.datasheetcatalog.org/datasheet...oc4136.pdf

the pages relating to EEPROM are between 40 and 42, and include the EECON SFR.

Other possibly noteworthy information:

my Program is written on a 32K FLASH memory which is sitting also externally and addressed between 0x0000 and 0x7FFF (So its overlapping with EEPROM) though I'm guessing the PSENALE is suppose to prevent data and code mixups.

this is my first MCU project, so I may have made a newbie mistake... Dont overlook the obvious stuff :)

Later edit:

I am pretty sure the fault is in the EECON SFR, because when I made a software that just toggles EEPROM on and off while displaying "checkpoint" message on the LCD.

	lcd_display("Starting",0,0); //Start Checkark
	EPROM_Normal();
	lcd_display("EEPROM ON",0,0); //Enable EEPROM Checkmark
	EPROM_Shutdown();
	lcd_display("EEPROM OFF",1,0); //Disable EEPROM Checkmark, display on line 2

 


only the Starting and EEPROM OFF messages were displayed, the EEPROM ON was completely. the only think that seem to happen was a delay between the "Starting" and "EEPROM OFF" messages (~around 3 seconds delay)

heres the EPROM functions for refrence:
void EPROM_Normal()
{
EECON=0x02;	//Allow usage of EPROM
//AUXR=0x0C;	//Restore normal R/W Cycles						  
}

void EPROM_Shutdown()
{
EECON=0x00;	//Allow usage of EPROM
//AUXR=0x0C;	//Restore normal R/W Cycles						  
}
 


as you see, I commented out the AUXR to rule him out, leaving just EECON as problem source.

can someone please help me out this I really need to finish this project by Wednesday.

heres the image of the EECON SFR:



and heres the AUXR SFR:



List of 23 messages in thread
TopicAuthorDate
EEPROM Read/Write Issues            01/01/70 00:00      
   if it was an external EEPROM            01/01/70 00:00      
   if it was an external EEPROM            01/01/70 00:00      
   Special sequence.            01/01/70 00:00      
      Thanks, but can you please simplyfy it?            01/01/70 00:00      
         Hope this explains            01/01/70 00:00      
   Managed to fix lockups, but it doesnt read/write            01/01/70 00:00      
      You have to choose your API            01/01/70 00:00      
         Already did all that            01/01/70 00:00      
            char vs int            01/01/70 00:00      
            I gave you a function            01/01/70 00:00      
               Still no luck            01/01/70 00:00      
                  unsigned int is not the size of the unsigned int* pointer            01/01/70 00:00      
                  Why not use the function I gave you.            01/01/70 00:00      
                     I did use you function            01/01/70 00:00      
                        My apologies.            01/01/70 00:00      
                           Sorry to keep dragging you back here...            01/01/70 00:00      
                              FLIP is a pain            01/01/70 00:00      
                                 We have progress!            01/01/70 00:00      
                                    Terribly sorry to bump but I really need help            01/01/70 00:00      
                                       Found the solution!            01/01/70 00:00      
                                          Study your C textbooks            01/01/70 00:00      
                                          it cant distinguise the sign bit            01/01/70 00:00      

Back to Subject List