AnsweredAssumed Answered

Eeprom woes with MC9S12DT256CFU

Question asked by John Tortorice on Jul 20, 2009
Latest reply on Jul 27, 2009 by stanish

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

Outcomes