Dear Sir, I am trying to write in sector-0 of flsh memory of LPC 2144. The code gets compiled and hex file is generated successfully. But when I read from it, currupt data is obtained. Is there any extra precaution required in writing to sector-0 or is it allowed or not to write in sector -0. However I am able to read and write in other sectors of the same successfully. Following code is used: #define IAP_LOCATION 0x7FFFFFF1
char Ram_Array[] = "TEST WITHOUT PEN DRIVE SEC. 0 ";
unsigned long command[5]; // For Command Table
unsigned long result[2]; // For Result Table
typedef void (*IAP)(unsigned long [], unsigned long []);
IAP iap_entry;
void main () {
unsigned long i,j; char a1,a2,a3,a4; char *FlashPointer; char *Ram_Pointer;
InitSystem(); PINSEL0 = 0x00050000 ; iap_entry = (IAP)IAP_LOCATION;// Set Function Pointer Ram_Pointer = (char*)0x40000100; // Set pointer to RAM for (i=0;i<256;i++) { if(i<=30) *Ram_Pointer = Ram_Array[i]; else *Ram_Pointer = '0'; Ram_Pointer++; }
Write_to_Flash(1,1,256,0x1000);
while(1);
}
void Write_to_Flash(unsigned char Start_Sector, unsigned End_Sector, int No_of_Bytes, unsigned long Mem_Addr) { command[0] = 50; // Prepare sector(s) for a Erase Operation command[1] = 0; command[2] = 0; iap_entry(command,result);
command[0] = 52; command[1] = 0; command[2] = 0; command[3] = 48000; // PCLK == 48000 KHz iap_entry(command,result);
command[0] = 50; command[1] = 0; command[2] = 0; iap_entry(command,result);
command[0] = 51; command[1] = 0x00000000; command[2] = 0x40000100; command[3] = 256; command[4] = 48000;// PCLK = 48000 KHz iap_entry(command,result); }
Kindly suggest.
Vikas