AnsweredAssumed Answered

I can not write data to Flash memory

Question asked by Alireza Bolourchian on Aug 13, 2009
Latest reply on Aug 14, 2009 by bigmac

Hello everybody,

I am developing a project with CodeWarrior IDE 5.9.0 and Processor Expert.

I am working with 16 bit MCU – 9S12E128QFP80 with PE BDM and simulation program.(Visualizing)

The problem is, I can not write data in the flash memory. Actually I am trying to use the address at  0x4000 or 0x8000 but every time I try to get value  but the status is showing error (ret = FF) and also after programming when the program is running every things will mix up and I should disable the bean protection option to run the program again..

I used the flash int. bean with no protection for flash memory. I believe something is missing here.

 In attachment you have the main program setup picture for bean and in the following you have the program.

Please help me.

Thanks

 

 

-------------------------------------------------------------------------------------------------------------

 

 

/* MODULE Project11_00 */

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "AI0.h"
#include "K1.h"
#include "K2.h"
#include "K3.h"
#include "K4.h"
#include "Glob_load.h"
#include "LED_G1.h"
#include "LED_G2.h"
#include "LED_R1.h"
#include "LED_R2.h"
#include "Buzzer.h"
#include "GP_Enable.h"
#include "TI1.h"
#include "TI2.h"
#include "ShutDown.h"
#include "FLASH1.h"
#include "Pump_1_Bit.h"
#include "Pump_2_bit.h"
#include "BF_1.h"
#include "BF_2.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include <stdio.h>
#include <math.h>




 unsigned char F_WRT(void);
 unsigned char F_ERASE(void);
 unsigned long ratio=0,cnt_00=0,cnt_02=0,cnt_03=0;
 
 volatile long int x0,x1,x2,x3,x4,Pressure_0,Temp_1,Temp_2,Temp_3;
 float  y2,Volt_1,Volt_2, Volt_3 ;

 
 volatile short i=0;
 
 bool key1=FALSE,pb1=FALSE,pb2=FALSE,pb3=FALSE,pb4=FALSE,i1= FALSE;
 bool FL00=0,FL01=0,FL02,FL03,FL04;
 unsigned char cnt_01=0,dt=100;
 unsigned int data[4] @0x4000;
 unsigned char R1,ret;



unsigned char F_WRT(void)
      
        {
          FCMD = 0x20;
          FSTAT = 0x80;
                ret = 0xFF;
          if(!FSTAT&&FSTAT_PVIOL_MASK)
             if(!FSTAT&&FSTAT_ACCERR_MASK)
              ret = 0x00;
          return ret;
         
         
        }


        unsigned char F_ERASE(void)
      
        {
          FCMD = 0x40;
          FSTAT = 0x80;
                  ret = 0xFF;
          if(!FSTAT&&FSTAT_PVIOL_MASK)
             if(!FSTAT&&FSTAT_ACCERR_MASK)
                ret = 0x00;
          return ret;
         
         
        }
          





void main(void)
{
 
 
 
  /*  local variable definition  */
 
       word value[1];
 
       ShutDown_ClrVal();


  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
 
 
 
 
    for (R1=0; R1 < 4; R1++ ) {
     
       data[R1]=0;
       ret = F_ERASE();
    }
 
    R1 = 0;
    data[R1++] = 0x00;
    data[R1++] = 0x01;
    ret = F_WRT();
    data[R1++] = 0x02;
    data[R1++] = 0x03;
    ret = F_WRT();
  
       for(;:smileywink:{   .........................................................................................}
  

 

 

Code warrior_1.JPG

Message Edited by t.dowe on 2009-09-02 03:19 PM

Outcomes