Maker Pro
Maker Pro

Program memory offset - Reset is occurring at any interrupt

esm.

Feb 19, 2012
26
Joined
Feb 19, 2012
Messages
26
Hi.

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.

BOOTLOADER CODE:
RESET ADDRESS = 0x0000
INTERRUPT ADDRESS = 0x0004

APP CODE:
RESET ADDRESS = 0x0400
INTERRUPT ADDRESS = 0x0404

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?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,699
Joined
Nov 17, 2011
Messages
13,699
Hi,
although I'm completely unfamiliar with the PIC series, here's an idea:
As far as I understand, the reset address and with it the addresses of the interrupt vectors are always at 0x0000 upward. So an interrupt will always occur at low addresses, regardless of the address space layout of your application. This is often hardwired in the chip.
So you may have to split your problem in two:
1) relocate the app to 0x400
2) leave the interrupt vectors at 0x000 upwards.

Regards,
Harald
 
Top