I have a function thats supposed to write to a flash location, so i need to execute it from RAM. But when i step through the program i notice that it skips my function and returns to start.. And when i check if anything was written to flash i see thats its still empty. I am using the DMA to transfer the data from a buffer to the specified location. And i have checked my functions are working correctly, but when i choose to run it from SRAM nothing happens.
What am i doing wrong?
//------------------Valuable Code--------------------//
// Running write function from RAM //
// The problem is that it steps over the function //
// //
//--------------------------------------------------- //
//Write program from 0x4800-0x5FFF to XDATA 0x0000-1FFF (SRAM)
cnt = 450;
ProgramPointer = (unsigned char)((unsigned int)(0x0000));
pg = 9;
Read_Flash(pg,offset,ProgramPointer,cnt);
//Erase the page we want to write to
pg = 5;
cnt = 8;
offset = 0;
Erase_Flash(pg);
//Map XDATA 0x0000-1FFF to SRAM and execute from SRAM
MEMCTR |= 0x08;
//Run the function from RAM
//Call function in SRAM
asm("LJMP 0x8000");
//Check for the written values.
cnt = 450;
ProgramPointer = (unsigned char)((unsigned int)(0x0000));
pg = 5;
Read_Flash(pg,offset,ProgramPointer,cnt);
Thanks for any reply!