Program memory offset - Reset is occurring at any interrupt

Support for Bloader and Screamer

Moderator: phalanx

Post Reply
Posts: 7
Joined: Sun Feb 19, 2012 3:16 pm

Program memory offset - Reset is occurring at any interrupt

Post by esm. » Fri Feb 24, 2012 3:15 pm


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.



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?

Posts: 418
Joined: Thu Apr 26, 2012 6:59 pm
Location: Lima, OH

Re: Program memory offset - Reset is occurring at any interr

Post by Joeisi » Thu May 03, 2012 6:22 pm

You could be going over the max memory, so it rolls back to 0x0000 when it goes through all of its instructions it loops back. This is improbable, but possible. Otherwise...... IDK.

Post Reply