Using the EEprom with codewarrior

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

Using the EEprom with codewarrior

5,493 Views
pieboy42
Contributor I
I'm using codewarrior to program my HC908AB32 processor, but with only partial success.

I can use the emulator to read and write to the processors eeprom, but when I'm running the program form the actual chip it doesn't seem to write to the eeprom.

It reads ok, but I'm I'm reading is the 0xFF's that are default in the eeprom.

I'm using the processor expert to generate the code, which is as follows:


  word address001;
  byte data;
  char tim=0;
 
   EENVR &= 0xF0;
   address001 = 0x0800;
   while (tim < 12){
 
      data = progmodemenu[tim];
      IEE1_SetByte(address001,data);
      address001++;
  
      data = (progmodemenu[tim]>>8);
      IEE1_SetByte(address001,data); 
      address001++;
   
      tim++;
   }


Do I need to do anything else to set the processor up for programming?

Thanks for the help


Message Edited by pieboy42 on 2008-12-17 06:17 PM

Message Edited by pieboy42 on 2008-12-17 06:19 PM
Labels (1)
Tags (1)
0 Kudos
10 Replies

1,175 Views
Evgenij
Contributor III
Hi everybody. Happy New Year.
I have question about working with EEPROM of mc68hc912bc32 using C. I've worked with EEPROM of AVR microcontrollers, but there are some other principles of working with it. Please, can you consult me?
I've read carefully manual and created the next code:
//this code must write some data to EEPROM position
uchar EEPROM_Write(unsigned short* addr) {     //addr - address of EEPROM position
    EEPROT = 0;                                  //unprotect sections of EEPROM
    EEPROG = 0b00000010;               //set EELAT
    *addr = 3231;                                  //write to addr position data 3231
    EEPROG |= 1;                                //set EEPGM (turn on voltage converter)
    EEPROM_Wait();                           //wait nearly 10 ms
    EEPROG = 0;                                 //turn off
    return 1;
}
This code doesn't work. I mind doesn't work that there are no changes in memory map in simulator (EEPROM 0x0d00 - 0x0fff).
Can you say me something about that? Thanks.
0 Kudos

1,174 Views
CrasyCat
Specialist III
Hello
 
Did you see this thread?
It might be helpful in you case as well.
 
CrasyCat
0 Kudos

1,174 Views
pieboy42
Contributor I
I had a look there, but it wasn't quite the same problem.

I'm still able to use the read/write the eepromy when it's running on my emulator, but when actually running on the chip I cant write to the eeprom.
0 Kudos

1,175 Views
stanish
NXP Employee
NXP Employee
Hi pieboy42,

How do you check that EEPROM write is not ok without using debugger/emulator?
Is the rest of the application executed correctly?
e.g. Watchdog timer might reset your MCU therefore the code execution might not reach EEPROM read/write routines.

Stanish
0 Kudos

1,175 Views
pieboy42
Contributor I
Stanish

In my program I save data to the eeprom, and at a later point load it and display it on my leds. (I use the eeprom so the data remains even after a power cut)

When I use my emulator I can see it displayed on the leds (so I know it has saved then loaded again), and also in the memory map section of my emulator.

When I'm using the chip in it's target application the data only reads back all 1's, which is the default un-programmed state of the memory.

Apart from that the program works fine on both emulator, and in target application, the rest of the code is executing perfectly.

The only difference is the speed, for some reason the emulator runs slower.

Richard
0 Kudos

1,174 Views
stanish
NXP Employee
NXP Employee
I'd suspect that the different timing might cause this problem. EEPROM erasing and programming require specific timebase (35us according to the datasheet).

Which cable are you using?
Which version of CodeWarrior? (menu Help ->About ->"Installed Products")

Stanish
0 Kudos

1,175 Views
pieboy42
Contributor I
Stanish

The target board is running the correct speed (as far as I know), I think the emulator is the one that is running slower than it should be.

My emulator is a M68MMEVS05 with M68EML08AB32 Daughter board.

I'm using the cable that came with the emulator, a 64 pin brown flat ribbon cable type 01-RE90433W01

Codewarrior IDE version 5.6.1.1506
Codewarrior development studio for motorola HC08 3.1 build 4210

The processor expert bean inspector tells me that the oscillator frequency is 4.9152Mhz, which is the speed of the crystal on my target board.

Thanks

Richard
0 Kudos

1,175 Views
J2MEJediMaster
Specialist I
Richard:

EEPROM writes take along time (relatively speaking), so it's possible that the watchdog timer is expiring and resetting the MCU on you. The debugger automatically disables the watchdog timer, which is why it works in the debugger. You need to extend the watchdog timer interval during the EEPROM writes or disable it temporarily.

---Tom
0 Kudos

1,175 Views
pieboy42
Contributor I
The watchdog is not cutting in, so that shouldn't affect it.

Because processor expert is doing all the work, it should just run.  I have tried checking the various registers that appear in the freescale datasheet, but they all seem to be set correctly (by processor expert)

It's frustrating, because I don't know where else to look.

I've tried changing the way i declare the various variables used for the save/load. 
I've tried setting the bits that disable security, and setup the programming.
I've checked the timing, and that all seems fine

here's an updated bit of my code, which just saves one byte, depending on the state of a button...

 unsigned int address001;
  unsigned char data;
 
  address001 = 0x0880;
 
  if (button1 & 0x10){
  data = 0x01;   
  } else {
  data = 0x10;   
  }

   IEE1_SetByte(address001,data);

Thanks for the help.
0 Kudos

1,175 Views
ProcessorExpert
Senior Contributor III
Hello Richard,

Write to EEPROM is not successful if the protection of the memory is enabled. You can check it by inspecting EENVR register (bits 0-3, address 0xFE1C). The protection of all blocks can be disabled using method SetProtection before any write/erase operation.

your code
......

IEE1_SetProtection(0xF0);   //disables protection of all blocks
IEE1_SetByte(address001,data);   

.....
your code

best regards
Vojtech Filip
Processor Expert Support Team
UNIS
0 Kudos