Write Data in the internal EEPROM of MC9S12DG128

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

Write Data in the internal EEPROM of MC9S12DG128

2,274 Views
cédricbouiron
Contributor II


Hello,

 

I encountered a problem with the internal EEPROM of MC9S12DG128 : if I do about 30 write and reset just after, sometimes some data are wrong.

The wrong value isn't always the last (sometimes but not always).

 

Precision : EEPROM was not protected.

 

How many EECLK are spend to write a WORD in the internal EEPROM of MC9S12DG128 ?

 

Should I wait a little before performing a reset ?

 

thanks for your support.

 

Cédric.

Labels (1)
Tags (3)
12 Replies

1,259 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

I would like also to add info about timing.

The formula to calculate EEPROM events are presented in the data sheet.

A.3.1.2 Row Programming

This applies only to the Flash where up to 32 words in a row can be programmed consecutively by keeping the command pipeline filled. The time to program a consecutive word can be calculated as:

The time to program a whole row is:

tbwpgm = 4 / fNVMOP + 9 / fbus;   Operating Frequency fNVMOP  = 150~200 kHz

Row programming is more than 2 times faster than single word programming.

tbrpgm = tswpgm + 31 ⋅ tbwpgm

Single Word Programming Time tswpgm 46 (2) ~ 74.5 (3) μs

2. Minimum Programming times are achieved under maximum NVM operating frequency fNVMOP and maximum bus frequency fbus.

3. Maximum Erase and Programming times are achieved under particular combinations of fNVMOP and bus frequency fbus.

Refer to formulae in Sections Section A.3.1.1 Single Word Programming- Section A.3.1.4 Mass Erasefor guidance.

μs

Best regards,

Ladislav

0 Kudos

1,259 Views
cédricbouiron
Contributor II

Hello Ladislav,

First of all, thank for your response.

For now I just cannot test your routine, because I work with WinIdea and write in Eeprom is automatically made by librairy provided by Cosmic.

Maybe it could be possible if I had time but I need to make it work right now without changing all the code.

Until now the better solution I find is to delay the reset by 500ms (200ms just doesn't work :smileyshocked:).

Actually it seems to be linked with another peripheral but I'm not sure.

Last thing, all interrupts are deactivated when data are witten.

Cedric.

0 Kudos

1,259 Views
cédricbouiron
Contributor II

Some news about this one,

In my opinion this issue may caused by some interactions with ADC peripheral.

Another possible issue is libe.h12 from cosmic.

Problem seems to be solve by :

1- Reset to 0 the fields to be written

2- Write all the value in one block (interruption deactived)

3- Reset

it works 100% until now (finger crossed).

Thanks for your help,

Cédric.

0 Kudos

1,259 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

There could be any hidden isue there. If I were you I would check EEPROM behavior without cooperation with another peripheral. Some problem could be that in the case of special single chip mode some registers are writeable which is not valid in the case of normal mode.

I would like you to test routines I have attached. It is written for DT128 but you can load it into DG128 directly, Please compare your routines with mine. Next thing I would like to mention is you should be sure you reset the MCU in correct time before routine is finished. (EEPROM setup is made for // OSCCLK=16MHz, BUSCLK=8MHz) The EEPROM divider setup is also attached.

The last thing I would suggest, in the case you use interrupts, is to create interrupt catcher routine where all unused interrupt are directed from their routines.

Best regards,

Ladislav.

0 Kudos

1,259 Views
kef2
Senior Contributor IV

Could you show your code for setting flash clock divider? ECLKDIV is write once register, which means that PRDIV8 and other ECLKDIV bits have to be written in one write cycle: ECLKDIV=xxx;

EEPROM word program is in progress while( (ECLK & ECLK_CCIF_MASK) == 0){}
Single word program, like specified in Electrical Characteristics in datasheed, takes 46..74.5 microseconds. Number of required bus clock cycles depends on oscilator clock frequency.

1,259 Views
cédricbouiron
Contributor II

Thanks for your reply,

here the initialisation of ECLKDIV :

ECLKDIV = FCLKDIV = 0x49;

According to Electrical Characteristics, single word program takes 48,125 µs in my application.

Maybe i should test CCIF bit before reset to be sure that there is not pending command before reset.

But, the thing is that the wrong value is not the last writed.

In addition, before resetting, i send the value that should be write and the value read in EEPROM on the bus

both this value are coherent.

But after reset the value in EEPROM is wrong ...

Cédric

0 Kudos

1,259 Views
kef2
Senior Contributor IV

Of course you should wait for CCIF before resetting MCU.

How do you verify value is wrong in EEPROM. I mean if you rely on CW debugger for this, then be aware that by default it caches read only memories like FLASH and EEPROM. To read real data, you need to first edit Memory mapping or Device memory mapping (I'm not cert about exact name) in Multilnk menu in debugger and tick required checkmark's to update areas in question on CPU halt.

0 Kudos

1,259 Views
cédricbouiron
Contributor II

Hello Edward,

Here the entire description of my problem :

1- The data is written in EEPROM at a specific address.

2- The EEPROM is read at the same address and the value is sent on the bus (CAN) just before reset.

3- This value is good.

4- µC resets.

5- During initialization, an internal test is initiated to determine if the value is OK.

6- But the value is wrong ...

With CW debugger is connected, the error never appears.

By adding a large delay before resetting, the problems seems to be solved.

Thank you for your interest.

Cédric.

0 Kudos

1,259 Views
kef2
Senior Contributor IV
  • With CW debugger is connected, the error never appears.

"Works with debugger, doesn't work without debugger" suggests looking for write once registers problem. Debugger usually operates in special single chip mode. In special single chip write once protection is disabled and wrong code may be able to init write once registers to right values.

  • By adding a large delay before resetting, the problems seems to be solved.

Is this large delay longer than word program time (CCIF==0)?

1,259 Views
cédricbouiron
Contributor II

Yes, the delay is about 500ms. Maybe it can be reduce but time for this application is not important. The most important is that the value are good after reset.

I will take a look at the write one registers.

Thanks for your help.

0 Kudos

1,259 Views
kef2
Senior Contributor IV

What triggers these writes to EEPROM? Is it some validated command send to MCU over CAN (CRC protected in hardware), over RS232 and CRC checksummed short command or quite long command like "WRITE"? You should make sure that new write command isn't triggered in the time period from write to EEPROM and reset command.

0 Kudos

1,259 Views
cédricbouiron
Contributor II

Written data  are ADC value.

Procedure is hardcode.

0 Kudos