??? 04/09/10 12:27 Modified: 04/09/10 12:33 Read: times Msg Score: +3 +3 Good Question |
#174943 - EEPROM Stuck |
I am having issues 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 distiguish 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: 1)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. 2)this is my first MCU project, so I may have made a newbie mistake... Dont overlook the obvious stuff :) |
Topic | Author | Date |
EEPROM Stuck | 01/01/70 00:00 | |
I do not know about Atmel, and ... | 01/01/70 00:00 | |
the problem is in the EECON SFR, just what in it? | 01/01/70 00:00 | |
EECON Initiate programming | 01/01/70 00:00 | |
to Joseph Hebert | 01/01/70 00:00 |