View previous topic :: View next topic |
Author |
Message |
bcs99
Joined: 22 Nov 2003 Posts: 32
|
GPS and INT_EXT problems |
Posted: Wed Dec 10, 2003 6:54 pm |
|
|
Why does the code below only run once? Is there an interrupt bit to reset? Any help would be greatly appreciated.
Code: |
#include <16F876A.h>
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=4800, xmit=PIN_B1, rcv=PIN_B0,stream=GPS)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=MODEM)
#define GPS_BUFFER_SIZE 70
static char GPS_buffer[GPS_BUFFER_SIZE];
static char GPS_code[] = "$GPRMC";
static char* GPS_p = GPS_buffer;
static int GPS_state = 0;
static short GPS_done = TRUE;
static short GPS_found = FALSE;
#int_ext
void GPS_isr()
{
char c;
c = fgetc(GPS);
if( GPS_found == FALSE )
{
GPS_found = TRUE;
}
if( GPS_state < 6 )
{
if( c == GPS_code[GPS_state] )
{
if( GPS_state == 0 )
{
GPS_p = GPS_buffer;
}
*GPS_p = c;
GPS_p++;
GPS_state++;
}
else
{
GPS_state = 0;
}
}
else
{
if( c == 0x0d ) // carriage return
{
*GPS_p = 0;
GPS_done = TRUE;
disable_interrupts(INT_EXT);
}
else
{
*GPS_p = c;
GPS_p++;
GPS_state++;
}
}
}
main()
{
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(TRUE)
{
if( GPS_found && GPS_done )
{
fputs(GPS_buffer,MODEM);
GPS_state = 0;
GPS_done = FALSE;
enable_interrupts(INT_EXT);
}
}
}
|
|
|
|
hal Guest
|
|
Posted: Wed Dec 10, 2003 9:46 pm |
|
|
What triggers the external interrupt?
Why disable interrupts inside an ISR? Aren't they disabled already? Won't they be enabled again as soon as the ISR exits?
Since the initial value of GPS_DONE is TRUE, and GPS_FOUND is set TRUE on the first interrupt, you will call fputs(GPS_buffer, MODEM) after the first interrupt, with uninitialized garbage in GPS_buffer. Could that be a problem?
Just trying to help.
-- hal -- |
|
|
bcs99
Joined: 22 Nov 2003 Posts: 32
|
|
Posted: Thu Dec 11, 2003 9:58 am |
|
|
Quote: | What triggers the external interrupt? |
Receive data on the GPS triggers on a high to low edge (H_TO_L).
Quote: | Why disable interrupts inside an ISR? Aren't they disabled already? Won't they be enabled again as soon as the ISR exits? |
I don't want the interrupt serviced again until later.
Quote: | Since the initial value of GPS_DONE is TRUE, and GPS_FOUND is set TRUE on the first interrupt, you will call fputs(GPS_buffer, MODEM) after the first interrupt, with uninitialized garbage in GPS_buffer. Could that be a problem? |
Sorry, GPS_done should have been FALSE. GPS_found should be set on the first interrupt, it informs the program that a data stream is available. It could be left out for this test program. GPS_buffer is initialized to zeros when declared static so fputs would have just sent a null string to the MODEM which would not be a problem.
However with GPS_done set to FALSE and code relating to GPS_found removed it still only sends once. GPS_state remains at zero after the first result is sent to the MODEM. |
|
|
bcs99
Joined: 22 Nov 2003 Posts: 32
|
error found! |
Posted: Thu Dec 11, 2003 10:21 am |
|
|
Quote: | #define GPS_BUFFER_SIZE 70
static char GPS_buffer[GPS_BUFFER_SIZE];
static char GPS_code[] = "$GPRMC";
|
GPS_BUFFER_SIZE is 70 and GPS_code follows it. If the string received is greater than 70 GPS_code gets over written and changes the match condition so that it never occurs again. |
|
|
|