Eeprom woes with MC9S12DT256CFU

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Eeprom woes with MC9S12DT256CFU

跳至解决方案
1,480 次查看
jct5016
Contributor I

Hello,

 

I am attempting to write to eeprom (0x400 to 0xFEF).  I am using:

 

CW 5.9.0

MC9S12DT256CFU (on an axiom CSM12DT256 Dev Board, 4MHz Xtal)

P&E USB Multilink REV C.

 

When I let the code run, it appears nothing happens.  The memory viewer in the debugger shows no change for any of the locations, and the only registers that seem to change are ECLKDIV, EPROT, and ECMD.

 

eeprom.c:

 

#include <std_types.h>
#include <hidef.h>     
#include <mc9s12dt256.h>

void eepromInit(void)
{
 ECLKDIV =  0x14; //FDIV = 4MHz / 20 = 190kHz
 ECNFG =  0x00; //No interrupts
 EPROT =  0x88; //No protect
 ESTAT =  0x30; //Clear status

 while((ESTAT&0x80)==0)
 {}

 ECMD = 0x60; //Erase all EEPROM
 ESTAT = 0x80; //launch command

 return;
}

void eepromWrite(uint16 address, uint8 data)
{
 uint16 *dataPtr, *addressPtr;
 short okToWrite;
 uint8 status, ACCERR, PVIOL, CBEIF;
 okToWrite = 0;

 PORTB_BIT4 = 0; //LED1 on

 CBEIF = 0;
 PVIOL = 0;
 ACCERR = 0;
 status = 0;

 addressPtr = (uint16*)(address);
 dataPtr = (uint16*)data;

 while((ESTAT&0x80)==0)
 {}
 /*
 while(!okToWrite)
 {
  status = ESTAT;
  ACCERR = (0x10 & status)/0x10;//bit mask to extract value of ACCERR from ESTAT Register
  PVIOL = (0x20 & status)/0x20;//same as above but PVIOL
  CBEIF = (0x80 & status)/0x80;//same but CBEIF

  if((!ACCERR) && (!PVIOL) && CBEIF)
   okToWrite = 1;
 }
 */

 *(addressPtr) = *(dataPtr); //latch data and eeprom loc                         

 ECMD = 0x20; //Program
    ESTAT = 0x80; //launch command
 while((ESTAT&0x80)==0){}   //waits for writing to end

 PORTB_BIT4 = 1; //LED1 off
 return;
}

main.c:

 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dt256.h>      /* derivative-specific definitions */
#include "eeprom.c"
#include <std_types.h>


#pragma LINK_INFO DERIVATIVE "mc9s12dt256b"

void main(void)
{
  uint8  writeData;
  uint16 i, address;
 
  DDRAB = 0xFFFF;                     

  writeData = 0x21; //exclamation point              
 
  eepromInit();
                              
 
  PORTB_BIT4 = 0; //led4 on
 
  for(i = 0; i < 50000; i ++){}//delay
 
  PORTB_BIT4 = 1; //led4 off
   
  for(address = 0x400; address < 0xFEF; address++)
      eepromWrite(address, writeData);
     
  PORTB_BIT4 = 0; //led4 on
 

}

 

 

 

 

 

 

Thanks,

 

JT

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
903 次查看
stanish
NXP Employee
NXP Employee

Hello jct5016,

 

This issue was already discussed on Forums. I'd suggest you to try to turn on the "Refresh memory when halting" option for the appropriate EEPROM item in the Debugging Memory Map window in the Debugger.

 

see e.g.:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=7585&query.id=1783#...

 

Stanish

Message Edited by stanish on 2009-07-27 03:32 PM

在原帖中查看解决方案

0 项奖励
回复
1 回复
904 次查看
stanish
NXP Employee
NXP Employee

Hello jct5016,

 

This issue was already discussed on Forums. I'd suggest you to try to turn on the "Refresh memory when halting" option for the appropriate EEPROM item in the Debugging Memory Map window in the Debugger.

 

see e.g.:

http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&message.id=7585&query.id=1783#...

 

Stanish

Message Edited by stanish on 2009-07-27 03:32 PM
0 项奖励
回复