Have you studied app note 2548 (AN2548.pdf) yet? It covers some of the basics of Flash programming.
http://www.freescale.com/files/microcontrollers/doc/app_note/AN2548.pdf
Pramodkorti wrote:The required data to be written into flash was kept in RAM first and then the write operation was carried out. Here I was not able to write more than two bytes. Second time the data to be written was kept in a seperate FLASH memory space and the same was tried, but I was not able to write more than two bytes.
Your programming routine fails not because source data is in bad place, but because flash programming routine itself is in bad place.
I agree to your statement, I had followed below method for placing the flash
programming routine in RAM:-
#pragma CODE_SEG __PIC_SEG __NEAR_SEG PIC_CODE
void __far Function(void) {
}
void __far NextFun(void) {}
#pragma CODE_SEG DEFAULT
char RamBuf[100];
void Test(void) {
void (*__far startFunPtr)(void)= Function;
void (*__far endFunPtr)(void)= NextFun;
void (*__far bufferFunPtr)(void);
char *__far startDataPtr;
char *__far endDataPtr;
char *__far bufferDataPtr= RamBuf;
int i=0;
CONV_FAR_FUN_TO_DATA_PTR(startDataPtr, startFunPtr);
CONV_FAR_FUN_TO_DATA_PTR(endDataPtr, endFunPtr);
CONV_FAR_DATA_TO_FUN_PTR(bufferFunPtr, bufferDataPtr);
while (startDataPtr != endDataPtr) {
RamBuf[i++]= *(startDataPtr++);
}
bufferFunPtr();
}
Please let me know if something is wrong here.
Regards,
Pramod