EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Problem with EEPROM in MC9S12D64

Started by panalogic2 July 21, 2008
I am developing code for a hand-held product that uses the MC9S12D64
processor. The product uses the internal EEPROM to store a number of
4-byte calibration values, generated when the product is calibrated.

I am using the PEMicro's Win32, PROG12Z and ICD12Z programs to
author, program and debug the code, connecting to the BDM via
PEMicro's Multilink USB Multilink interface. The code is written in
assembler.

The EEPROM is mapped to the $0800-0BFF address space by writing $09
to the INITEE register in the startup code. My EEPROM programming sub-
routine uses a sectormodify command followed by a wordprogram command
to store the 4-byte values (which are held in temporary RAM
locations). In a separate routine, I then compare the data in the
EEPROM with the data in RAM to ensure the values have been programmed
correctly. I then calculate a checksum over the entire EEPROM space
and store this as a 4-byte value to address $0BEC.

Now everything works just fine in BDM emulation mode, the data gets
correctly programmed and can be read back from the EEPROM after a
complete power-down/power-up of the whole system. However when I run
the product free-standing, it fails to store the values to EEPROM.

The EEPROM program routine appears to complete fully without errors,
but the data is nowhere to be found in the EEPROM address space.

One odd thing that I did find at the very beginning was that the
EEPROM write addresses increment in 16-bit steps rather than the
usual 8-bit. So it was necessary to include the following code to
adjust the incoming write addresses:

ldd etargetaddr ; incoming write address
subd #$800 ; calculate the sector address
lsrd ; divide by 2
addd #$800
std eaddrhi

I have also noticed when viewing the $0800-0BFF EEPROM data area in
the debug program that it is precisely duplicated at $0C00-0FFF.

Can anyone please offer any suggestions as to why the EEPROM
programming only works in BDM mode?

Well the problem was solved with the help of a tech support person from
Freescale.

I was writing to the EEPROM data and address registers (as I have
always done with HC05 and HC11 processors). However I didn't know that
the S12 series is different in that one needs to write directly to the
EEPROM address space (in the same way that you would write to a RAM
address) and then run the EEPROM program commands. Apparently when you
do this, the data that you write is stored in internal buffers and then
written to the relevant EEPROM address when you run the command.

The MC9S12D64 data sheets do not mention any of this (sigh).


The 2024 Embedded Online Conference