View previous topic :: View next topic |
Author |
Message |
andysan
Joined: 01 Oct 2004 Posts: 2
|
Problems with High-priority Interrupt |
Posted: Fri Dec 17, 2004 2:42 am |
|
|
Could anyone with experience tell me what is wrong with my piece of code?
I got this error message:
Error[126] C:\\interrupt_file.c : Invalid ORG range
I have tried reading on the net but nothing won't work.
My code:
void test_interrupt(int* packet_ptr)
{
int i = 0;
char c;
RCIF = 0;
c = serial_getch();
if (c == START_STRING)
packet_ptr[0] = c;
packet_ptr[i] = c;
i++;
if (c == END_STRING)
{
full_packet = 1;
}
#asm
retfie 1
#endasm
}
#ORG 0x08,0x0A
void Int_Handler_High(void)
{
if (RCIF = 1) //USART Receive Interrupt Flag bit test_interrupt(packet_buffer);
}
//***********************************************************
// MAIN
//***********************************************************
void main(void)
{
…… |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Dec 17, 2004 3:41 am |
|
|
A number of problems.
Because you have tried to use a fast return from interrupt I am assuming you are using an 18F series PIC.
You do not need to install your own high priority interrupt handler via the vectors unless you have multiple high priority interrupts.
Code: | #int_rda FAST
void Int_Handler_High(void)
// .. rest of handler here
// if you are using the lastest compiler you do not need
// to add the following as this bug has been fixed
#asm
retfie 1
#endasm
|
Your original code did a call and then a fast return from within the call. This would have broken the return stack (your program would crash). Make sure you do not call a function in the high priority interrupt handler that you also have called either in the mainline or the low priority handler.
Although I have implied you can use C code in the high priority interrupt handler, I am skeptical about doing so as you, not the compiler, are responsilbe for saving and restoring registers that could be changed by the high priority handler. Because the registers and memory locations used could change with each flavour (version) of the compiler this is a potential support nightmare. For this reason I suggest using assembler only in the high priority handler.
The following two lines do the same thing
Code: | packet_ptr[0] = c;
packet_ptr[i] = c; |
There is no point in incrementing I as it is a local variable that is initialised to zero on entry and is not used after incremented. I suspect you ment to have i defined and initialised as a global variable elsewhere and you probably also intended the code to look like this:
Code: | if (c == START_STRING)
i = 0;
packet_ptr[i] = c;
i++; |
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri Dec 17, 2004 11:26 am |
|
|
Also, using arrays will require to save some registers. I think FSR's, but you should inspect the generated asm to find them.
If you search for my previous posts, you will see a lot of fast interrupt problems that are solved now. |
|
![](templates/subSilver/images/spacer.gif) |
|