Reading and writting data from/to EEPROM-problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading and writting data from/to EEPROM-problems

1,845 Views
emilian
Contributor I
Hello I'm writting a code for MC9s12D64 and I need store data in internal EEPROM. I have written routines for writting and reading word data to/from EEPROM but it doesn't work. The code:
Code:
void initInternalEEPROM(){ ECLKDIV = ECLKDIV | 20; //frequency divider feeprom = 190 kHz wyslijByte(ECLKDIV); //clear flags  ESTAT |=  (PVIOL | ACCERR);}void writeToIntEEPROM(word* adress,word data){ while( !(ESTAT & CBEIF)); //wait until not ready ESTAT |= (ACCERR | PVIOL);  // clear errors //(*(word*)adress) = data; *adress = data; ECMD = CMD_PROGRAM; ESTAT |= CBEIF; //launch the command}word readIntEEPROM(word *adress){  while( (ESTAT & CCIF)!=CCIF ); //wait until EEPROM ready return (*adress);}

 
And my first question is what is the start and end adress of EEPROM memory. I read datasheet and I think that from 0x800 to 0x17FF but maybe I'm wrong or maybe this source code is incorrect. Can anyone help me?
Labels (1)
0 Kudos
2 Replies

457 Views
Lundin
Senior Contributor IV
Freescale recommends to place the EEPROM at 0x0800 but it is mapped at 0x0000 out of reset. Since the cpu registers are mapped at the same address, the registers will take precedence. What you need to do early on in the program (I recommend to do it in the reset vector) is to map both the EEPROM and the RAM to other addresses.

INITRM = 0x21; /* map RAM to 0x2000 */
INITEE = 0x09; /* map EEPROM to 0x0800 */


I also doubt your clock calculation. The EEPROM clock is prescaled as

osc clock / 20

So you would get 190kHz if you have a 3.8 MHz crystal. If you have a 4MHz crystal which I assume, you should pick another value, since you end up at exactly 200kHz which is the upper allowed limit. You don't want to overclock the EEPROM since unexpected things will happen then.

Unless this line is incorrect:

ECLKDIV = ECLKDIV | 20;

It certainly looks odd. Perhaps you ment

ECLKDIV = PRDIV8 | 20;

Though that doesn't make much sense either, it would mean that you crystal is 30.4MHz...
0 Kudos

457 Views
emilian
Contributor I
Hello
I have done what you suggested so I map both the EEPROM and Ram to the other addresses and it still doesn't work. I try to write a word to the EEPROM adress 0x800 and when I turn off then turn on the suply and read the same adress a have a value 0 so I know that it doesn't work. I don't know what kind of problem I do. I want to mention that I have 4 MHz cryscal and I set the bus frequency for 24 Mhz.
0 Kudos