View previous topic :: View next topic |
Author |
Message |
bcs99
Joined: 22 Nov 2003 Posts: 32
|
trouble with INT_EXT and GPS |
Posted: Sat Jan 10, 2004 2:19 pm |
|
|
I'm having trouble with a software RS232 using the INT_EXT interrupt for a GPS connection through an ST232 convertor. The GPS may or may not be present for this application. The program runs fine if the GPS is connected but seems to hang if the GPS is disconnected.
I'm guessing that it's just a setup problem. Any help would be greatly appreciated.
Bob
Code: |
#use rs232(baud=4800,xmit=PIN_B1,rcv=PIN_B0)
... GPS code
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7)
... LCD code
// PIC INITIALIZATION
void pic_init()
{
// setup port A
output_a(0);
set_tris_a(0b00010000);
// setup port B
output_b(0);
set_tris_b(0b00000001);
output_float(PIN_B0);
// setup port C
output_c(0);
set_tris_c(0b00000001);
output_float(PIN_C7);
setup_adc_ports(A_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_256);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,100,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
}
void main()
{
int state = MAIN_MENU;
pic_init();
lcd_init();
read_gps();
while(TRUE)
{
switch(state)
{
case MAIN_MENU: state = main_menu(); break;
// more states....
}
}
}
|
|
|
|
bcs99
Joined: 22 Nov 2003 Posts: 32
|
Problem solved? |
Posted: Sun Jan 11, 2004 11:55 am |
|
|
I'm not sure if this is the way to solve it correctly but what I did was enable the INT_EXT interrupt ONLY if there was activity on PIN_B0. Now it works fine. What I don't understand is why it hangs. If there is no activity the interrupt should not be called. Any insight into this would be appreciated.
Bob |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 11, 2004 12:45 pm |
|
|
The implication is that the INT_EXT pin does have transitions on it.
When you say that the GPS is "removed", do you mean that Pin B0
has nothing attached to it at all ? ie., is it floating ? This could cause
the problem. Or, do you still have the ST232 chip connected to B0 ?
The ST232 chip has internal pull-down resistors on its RS232 receiver
side inputs, so it should provide a constant high level to pin Pin B0.
Just to be sure -- On the ST232 chip, do you either pin 9 or pin 12
connected to Pin B0 on the PIC ? These are the two available receiver
outputs. Do you have pin 15 of the ST232 connected to ground ?
It should be. If you have an oscilloscope you should look at Pin B0
when the GPS is removed. It should be at about +5v.
I think you should post your #fuses statement and the read_gps()
routine. |
|
|
bcs99
Joined: 22 Nov 2003 Posts: 32
|
|
Posted: Wed Jan 14, 2004 12:06 am |
|
|
Quote: | Posted: Sun Jan 11, 2004 3:15 pm Post subject:
--------------------------------------------------------------------------------
The implication is that the INT_EXT pin does have transitions on it.
When you say that the GPS is "removed", do you mean that Pin B0
has nothing attached to it at all ? ie., is it floating ? This could cause
the problem. Or, do you still have the ST232 chip connected to B0 ?
The ST232 chip has internal pull-down resistors on its RS232 receiver
side inputs, so it should provide a constant high level to pin Pin B0.
Just to be sure -- On the ST232 chip, do you either pin 9 or pin 12
connected to Pin B0 on the PIC ? These are the two available receiver
outputs. Do you have pin 15 of the ST232 connected to ground ?
It should be. If you have an oscilloscope you should look at Pin B0
when the GPS is removed. It should be at about +5v.
I think you should post your #fuses statement and the read_gps()
routine.
|
The GPS is removed mean that it is physically disconnected from the db9 connection. The ST232 is still present and Pin_B0 is tied to it directly through a 330 ohm resistor. Pin 15 is connected to ground. Pin B0 is stable on the scope and at 4.9vdc.
Here are the #fuses.
Code: |
#case
#include <16F876A.h>
#device adc=10 *=16
#use delay(clock=20000000)
#fuses NOWDT, HS, NOLVP
#priority EXT,RTCC
|
I really don't think that the problem is in the GPS code. I've been using it for some time now with out any problems. I really believe it's a setup/initialization problem. I don't have a storage type scope so I can't monitor the lines very well. It works well now if I just check for activity first before enabling the interrupt. I have not had any problems since I made that change.
Bob
Bob |
|
|
|