LPC1788 IAP problem

Discussion in 'Embedded Systems and Microcontrollers' started by Lazar Urosevic, May 8, 2015.

  1. Lazar Urosevic

    Thread Starter New Member

    May 8, 2015
    1
    0
    I'm working on LPC1788, trying to use In Application Programming, and in one project where I implemented this code:

    #define IAP_BASE1 0x00030000
    #define IAP_BASE2 0x00038000
    #define IAP_BASE3 0x00040000

    int main(void) {

    BYTE podatak1, podatak2, podatak3;
    DWORD *pointer_podatak1, *pointer_podatak2, *pointer_podatak3;
    uart0();

    NVIC_DisableIRQ(TIMER0_IRQn);
    NVIC_DisableIRQ(TIMER1_IRQn);
    NVIC_DisableIRQ(UART0_IRQn);

    podatak1 = 0x33;
    podatak2 = 0x63;
    podatak3 = 0x84;

    iap_copy_to_flash(&podatak1, IAP_BASE1, 1);
    delay_1_ms();
    iap_copy_to_flash(&podatak2, IAP_BASE2, 1);
    delay_1_ms();
    iap_copy_to_flash(&podatak3, IAP_BASE3, 1);
    delay_1_ms();

    pointer_podatak1 = (DWORD*) IAP_BASE1;
    pointer_podatak2 = (DWORD*) IAP_BASE2;
    pointer_podatak3 = (DWORD*) IAP_BASE3;

    LPC_UART0->THR = *pointer_podatak1;
    delay_1_ms();
    LPC_UART0->THR = *pointer_podatak2;
    delay_1_ms();
    LPC_UART0->THR = *pointer_podatak3;
    delay_1_ms();

    while(1)
    {
    }

    }

    It works perfectly, but when I try to utilize it in my main project, I've got nothing written on flash memory locations I indicated. Here is the code in my main project to read and write from flash:

    #define OFFSET_ADDRESS 0x00030000
    #define OFFSET_VERSION 0x00038000
    #define OFFSET_SERIAL 0x00040000

    void write_to_flash (void) {
    BYTE i;
    DWORD *pointer_podatak1, *pointer_podatak2, *pointer_podatak3;

    iap_copy_to_flash(&display_address, OFFSET_ADDRESS, 1);
    delay_1_ms();

    iap_copy_to_flash(&version, OFFSET_VERSION, 1);
    delay_1_ms();

    for (i=0;i<8;i++) {

    iap_copy_to_flash(&serial_no, OFFSET_SERIAL+i, 1);
    delay_1_ms();

    }
    }

    void read_from_flash (void) {

    BYTE i;
    DWORD *pok_add, *pok_ver, *pok_serial_no;

    pok_add = (DWORD*)OFFSET_ADDRESS;
    display_address = *pok_add;
    delay_1_ms();
    if ((display_address > MAX_OUTDOOR_DISPLAY_ADDRESS) || (display_address < MIN_OUTDOOR_DISPLAY_ADDRESS)) display_address = UNI_ADDRESS;

    pok_ver = (DWORD*)OFFSET_VERSION;
    version = *pok_ver;
    delay_1_ms();
    if (version > MAX_FW_VERSION) version = 0;

    for (i=0;i<8;i++) {
    pok_serial_no = (DWORD*)OFFSET_SERIAL;
    serial_no = *pok_serial_no++;
    delay_1_ms();
    }
    for (i=0;i<8;i++) if (serial_no > 9) serial_no = 0;

    }

    display_address, version and serial_no[] are global variables which are forwarded to these two functions write_to_flash and read_from_flash. Anyone knows maybe what can cause the problem, even if the correct and working code is implemented in main project?
     
Loading...