Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Program memory offset - Reset is occurring at any interrupt

Status
Not open for further replies.

esm.

New Member
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?
 
hi

I like your bootloader idea. Not being a c programmer i cannot offer advice in that regard but you might want to look at the value of PCLATH when you do the goto 0x0404.
 
What code do you have at location 4? If it's just a goto you will have problems if you are in any bank except bank 0.

Edit, you may have to do context saving before the goto.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top