This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading from Flash Not Working

I have the following code for my LPC2138 that writes to RAM, writes to ROM through IAP call, and then checks to see if it wrote to RAM and ROM correctly:

void testMem(){
        unsigned char index;
        unsigned command[5];
        unsigned result[5];
        int i;
        char Ram_Arry[] = "Hello World ";
        char* Ram_Pointer;
        u08 text[11];
        u08 text2[20] = "WHAT THE    ABCDEFG";
        IAP iap_bypointer;
        iap_bypointer = (IAP) 0x7FFFFFF1;                       //set IAP entry address in function pointer

        Ram_Pointer = (char*) 0x40004000;                                       //Set pointer to RAM

        for (index = 0; index<0x0C; index++){                //Copy data to be written to flash into the RAM
                *Ram_Pointer = Ram_Arry[index];
                Ram_Pointer++;
        }

        command[0] = 50;                                                        //Prepare sector five for a write operayion
        command[1] = 15;
        command[2] = 15;
        iap_bypointer(command,result);

        clearScreen();
        switch(result[0]) {
                case 0:
                        writeText("success ");
                        break;
                default:
                        writeText("something went wrong ");
                        break;
        }

        command[0] = 51;                                                   //write 256 bytes from address 0x40004000
        command[1] = 0x00040000;                                   //to 0x00005000 in flash memory;
        command[2] = 0x40004000;
        command[3] = 256;
        command[4] = 14000;                                                // see erase comment above
        iap_bypointer(command,result);

        switch(result[0]) {
                case 0:
                        writeText("success ");
                        break;
                default:
                        writeText("something went wrong ");
                        break;
        }


        Ram_Pointer = (char*)0x40004000;
        for(i=0; i<12; i++) {
                text[i] = *Ram_Pointer;
                Ram_Pointer++;
        }
        delay(DELAY_WAIT);
        Ram_Pointer = (char*)0x00040000;
        memcpy(&text2, &(*Ram_Pointer), 11);
        /*
        for(i=0; i<11; i++) {
                text2[i] = *Ram_Pointer;
                Ram_Pointer++;
        }
        */
        i2cMasterSendNI(0x50, 0xC, text);
        i2cMasterSendNI(0x50, 0x14, (u08*)text2);
}

This output's to my LCD as:

success success Hello World @(@@' ABCDEFG"

I thought you just read from Flash by simply giving the address location of the data you wish to copy? I'm sure I'm missing something small, but if you can't see anything wrong with my code, can you outline the process for reading from flash into RAM?