Program memory offset - Reset is occurring at any interrupt

Discussion in 'Embedded Systems and Microcontrollers' started by esm., Feb 24, 2012.

  1. esm.

    Thread Starter Member

    Jan 20, 2012

    I'm working with a PIC16F1938 MCU (Microchip)

    I did an offset on program memory (for APP CODE), in Hitec-C v9.83 compiler.
    I'm using a offset of 0x400 (this PIC has UART bootloader), configuring this offset at Project->BuildOptions->Linker->CodeOffset option.

    The issue is that when an interrupt occurs, the PIC resets itself.
    When i don't use the offset (not using offset and proggraming the PIC using an official programmer, PICKIT2), the code works correctly.

    The bootloader is UART1 based.

    RESET ADDRESS = 0x0000

    RESET ADDRESS = 0x0400

    The system works this way:

    1) The PIC is powered-up and the PIC processor goes to the reset vector (0x0000)

    2) The BOOTLOADER CODE runs and checks if a 0x01 (value) is stored at the first EEPROM address. If YES, it calls the bootloader task (transfer of a new APP CODE, starting from 0x0400 address). If NOT, the next intruction is a goto 0x0400 (start address of APP CODE). Interrupts are disabled on BOOTLOADER CODE (INTCON.GIE = 0). When the new APP firmware is received correctly, it writes 0x00 to the first EEPROM adress and resets itself (this time the PIC won't run the bootloader code again, it will go to the APP CODE start address, goto 0x0400)

    3) I'm using HitechC v9.83 compiler, where I defined, for the APP code, a reset vector of 0x0400 and interrupt vector address of 0x0404.

    4) When I need to update the APP firmware, I send some data bytes (a defined sequence of values) via UART1 to the PIC16F1938. If the this byte sequence is received correctly by the 16F1938, it writes 0x01 value to the first EEPROM address and reset itself (in order to run the BOOTLOADER CODE again, the firmware update function).

    5) When an interrupt occurs in the APP CODE, the processor goes to 0x0004 adress. The intruction stored at this address is a goto 0x0404 (the PIC processor would go to the interrupt defined in the compiler).

    The problem is that when the first interrupt occurs in the APP CODE, the PIC resets or maybe gets stuck doing something I don't know what is.

    When I'm not using program memory offset (when I transfer the APP FIRMWARE CODE to the 16F1938 normally using a PICKIT2 or PICKIT3, reset vector = 0x0000 and reset vector = 0x0004 on Hitech C compiler), the APP CODE works fine. I don't know whats happening, what I am doing wrong.

    Somebody could help?
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Memory address 0x0004 is the interrupt vector, meaning it typically holds a goto instruction where the real code is kept. Even though your bootloader does not use any interrupt services it should still vector interrupts to where they will ultimately be handled by the app code.
  3. t06afre

    AAC Fanatic!

    May 11, 2009