CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GPS and INT_EXT problems

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bcs99



Joined: 22 Nov 2003
Posts: 32

View user's profile Send private message

GPS and INT_EXT problems
PostPosted: Wed Dec 10, 2003 6:54 pm     Reply with quote

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







PostPosted: Wed Dec 10, 2003 9:46 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 11, 2003 9:58 am     Reply with quote

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

View user's profile Send private message

error found!
PostPosted: Thu Dec 11, 2003 10:21 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group