Mc13213 write/read eeprom

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

Mc13213 write/read eeprom

1,788 Views
kimegliodime
Contributor I
Hi,
i have some problem for programming eeprom in my mc13213.
i have a 13213SDK board.
the question is: exist any exsample for this board??

thank you


max
Labels (1)
0 Kudos
1 Reply

276 Views
jah
Contributor I
program eeprom haha.
there are a few tips, when i did a search most of what came up was busted junk code. when i re invented the wheel i submitted some more busted junk code. you can look for it. the how to for flash read/write should be in a seperate section as reference material or in the product spec itself but is not and causes countless confusion, a bad for freescale. my usage of _assy code is cleaner that what i have seen but i can only verify it works for me, good luck.

few tips:
-the routine that writes to eeprom needs to be in ram. people usally write in in assy but it dosnt have to be. now think about this, if the processor state machine is handling the flash write the internal bus structure is tied up and cant access flash program memory to support flash emulation. put the emulation code in ram.
-my processor is a mc9s08rd32dwe, and it could would be different on alot of processors, what is your processor? i dont even know if mine is close to yours
-the process to write even one byte to flash is:
0)you will need to set the flash timing in relation to the processor clock, do this up front in initiliaztion.
1)determine the 512 page where the byte is located in flsh and write the whole thingy to ram
2)modify the page in ram
3)erase that page in flash
4)wrtie from ram to flash the modifyed data
5)you might want to verify at this point flash = ram for that page
6)before while writting flash you might want to look for low battery
7)disable irq while writting
8)general note, the assy program has details that freescale outlined in the manual about cking for errors and things

//sample code:
//excerpt form initilization
// ** Flash Init
if(FSTAT & 0x10) FSTAT &= 0x10; //reset flash error if any, then set flash clock devider
FCDIV = 0x27; //for 8mhz per freescale datasheet p50 table 4-6

//excerpt form varriables.c
//code example flash memory page erase & byte write
// FlashRamRoutine.Adr = 0xE001;
// FlashRamRoutine.Data = 0xFF;
// FlashRamRoutine.Command = 0x40;
// _asm jsr FlashRamRoutine.Start;
// FlashRamRoutine.Adr = 0xE000;//byte write
// FlashRamRoutine.Data = 0xBB;
// FlashRamRoutine.Command = 0x20;
// _asm jsr FlashRamRoutine.Start;
#pragma DATA_SEG _RAMROUTINE
struct flashramroutine FlashRamRoutine = {
{0xc6,0x18,0x25,0xa5,0x10,0x27,0x07,0x45,//start instruction bytes
0x18,0x25,0xf6,0xaa,0x10,0xf7,0x32,
0x08,0x43, //address of unsigned int address
0xc6, //instruction byte
0x08,0x45, //address of unsigned char data
0xf7,0xa6}, //instruction bytes
{0x00}, //unsigned char command
{0x45,0x18,0x25,0xe7,0x01,0xf6,0xaa,0x80,//final instruction bytes
0xf7,0x9d,0x9d,0x9d,0x9d,0xc6,0x18,0x25,
0xc6,0x18,0x25,0xa5,0x40,0x27,0xf9,0x81},
0,0};//value of uint address, uchar data
#pragma DATA_SEG DEFAULT

//excerpt form varriables.h
#pragma DATA_SEG _RAMROUTINE
extern struct flashramroutine {
const unsigned char Start[22];
unsigned char Command;
const unsigned char End[24];
unsigned int Adr;
unsigned char Data;
} FlashRamRoutine;
#pragma DATA_SEG DEFAULT

//in my *.prn linker command file
SEGMENTS
RAMROUTINE= READ_WRITE 0x0814 TO 0x0845;
END
PLACEMENT
_RAMROUTINE INTO RAMROUTINE;
END

//usage
//copy whole flash page to ram
for(i=0x1FF; i+1; i-- ) PatchRAM[i] = *((unsigned char*)((patch.adr & 0xFE00) + i));

//after doing this code modifies copied ram version with new data and re-writes back

//copy modified ram page to flash
FlashRamRoutine.Adr = patch.adr-1; //erase whole flash page
FlashRamRoutine.Command = 0x40;
_asm jsr FlashRamRoutine.Start;
FlashRamRoutine.Command = 0x20; //write whole page to flash from ram
for(i=0; i0x200; i++){
FlashRamRoutine.Adr = (FlashRamRoutine.Adr & 0xFE00) + i;
FlashRamRoutine.Data = PatchRAM[i];
_asm jsr FlashRamRoutine.Start; }

Message Edited by jah on 2006-11-0610:23 AM

Message Edited by jah on 2006-11-0610:27 AM

0 Kudos