Not able to use Flash for buring data (as ROM)

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

Not able to use Flash for buring data (as ROM)

1,987 Views
R_D
Contributor I
Hi,

  I am using MC9S08AW16, trying to burn the flash region with some data to use it as ROM, i used the program given in the HCS08_Peripherals_Module_Quick_Reference_Users_Guide, that program does not work and not able to understand the algorithm given in the data sheet. especially about using FCBEF ( Write 1 to FCBEF to launch command and clear FCBEF). In the full chip simulation it says using unintialliatized location, when programmed is on the chip, only first location is burnt with data other locations are not burnt. Also when I enable channel interrupts in the program and use full chip simulation, interrupt does not occur. But works properly when program is in the chip.

code in the reference material:

//Array of opcode instructions of the Erase/Program function
//Element 0x14 of the array is: (command 0x20 to program a byte, 0x40 to erase a page)
unsigned char FLASH_CMD[] {
0x87,0xC6,0x18,0x25,0xA5,0x10,0x27,0x08,0xC6,0x18,0x25,0xAA,0x10,0xC7,0x18,0x25,
0x9E,0xE6,0x01,0xF7,0xA6,0x20,0xC7,0x18,0x26,0x45,0x18,0x25,0xF6,0xAA,0x80,0xF7,
0x9D,0x9D,0x9D,0x9D,0x45,0x18,0x25,0xF6,0xF7,0xF6,0xA5,0x30,0x27,0x04,0xA6,0xFF,
0x20,0x07,0xC6,0x18,0x25,0xA5,0x40,0x27,0xF9,0x8A,0x81};
/* The opcode above represents this set of instructions
if (FSTAT&0x10){ //Check to see if FACCERR is set
FSTAT = FSTAT | 0x10; //write a 1 to FACCERR to clear
}
(*((volatile unsigned char *)(Address))) = data; //write to somewhere in flash
FCMD = 0x20; //set command type.
FSTAT = FSTAT | 0x80; //Put FCBEF at 1.
_asm NOP; //Wait 4 cycles
_asm NOP;
_asm NOP;
_asm NOP;
if (FSTAT&0x30){ //check to see if FACCERR or FVIOL are set
return 0xFF; //if so, error.
}
while ((FSTAT&0x40)==0){ //else wait for command to complete
;
}*/



Labels (1)
0 Kudos
5 Replies

988 Views
R_D
Contributor I
Hi Jim,

              Thanks a ton. Yes I  made sure about that, was about ~192Khz.
0 Kudos

988 Views
R_D
Contributor I
Hello


    Please do put the project I am stuck with it for now, operating the MCU with bus clock of ~19.9968MHz
0 Kudos

988 Views
JimDon
Senior Contributor III
I will this evening, but are you sure that you are setting the flash clock correctly?
That could be your problem.

0 Kudos

988 Views
JimDon
Senior Contributor III
Ok, here is a link to a Processor Expert project that programs flash on an AW16.
Since it is a processor expert project, you can easily adjust the clocks as you wish.
Currently the clock is set for a 16Mhz bus clock. If you connect a serial port with a terminal emulator at 9600 baud you will get a prompt - type h for help. There is also code for a serial eeprom, but ignore that.
Study the flash init bean, and the code in flash.c.

If you have any questions, ask them..
0 Kudos

988 Views
JimDon
Senior Contributor III
All I can say is "does so".
Assuming you have transcribed it correctly, I have used that exact code on an AW and it worked.
I am away from the lab right now, but later I wll post a CW project for the AW that I have tested.
Also search this forum, as there have been many recent threads on this subject.
You do realize that the code in the array must run from ram.
See search box at the bottom....
0 Kudos