PDA

View Full Version : SERIN2 - "Timeout" hangs if > 255



flotulopex
- 10th July 2010, 22:15
Hello There,

I have been working on a tiny GPS project and while I was tuning the code, I noticed that the timeout set to more than a value of 255 would always make the program hang (!).

After googeling a few hours around, I couldn't find a specific answer to my "problem".

Is this value limit mentionned somewhere in the docs or is there something wrong with my code?

LinkMTech
- 11th July 2010, 00:29
Is this value limit mentionned somewhere in the docs or is there something wrong with my code?

I wonder if "Timeout" is defaulted to byte size and may need to be declared Word size before assigning a value to it?

mackrackit
- 11th July 2010, 02:34
Try

SERIN2 GPSfrom,Gpsbps,2500,NoGGA,[WAIT("$GPGGA")]

flotulopex
- 11th July 2010, 07:51
Either declared as WORD or value stated in the command, if > 255 the program will hang....

But I did some additional tests with value from 256 up to 999; from time to time, the program will resume. Nevertheless, the value expressed in milliseconds is never corresponding (time is far far longer, can last over minutes!).

Values over 999, will make the program never resume.

My circuit is simple:
PIC16F690 - 4MHz Xtal
GPS module GLOBALSAT em-406a + 10k pull-up on TX
LCDisplay in 4bits mode

I use MCS standard 3.0.0.5 + PBP2.50C.

mackrackit
- 11th July 2010, 09:48
DOH!!
I was not really thinking about your application when I answered before.
The TIMEOUT option will not work for you because the GPS is always sending something. All the TIMEOUT does is looks for the absence of a signal. If the GPS was turned off then TIMEOUT could be used to indicate that.

flotulopex
- 11th July 2010, 10:28
Thanks mackrackit,

For info, my GPS module sends data @ 1Hz interval. As long as I set my timeout value < 255, the expected result will occur.

Are your saying that timeout will not work if the expected character string OR any signal is received whithin the timeout value? I'm confused.

I use this modified (in red) routine to check if a particular NMEA sentence is sent by the GPS module. In that way, SERIN2 will receive signals and still have the timeout (<255) working - or is this test not valid?
CHECK_GGA:
SERIN2 GPSfrom,Gpsbps,Timeout,NoGGA,[WAIT("$GPxxxGGA")]
GOTO GPGGA:
NoGGA:
LCDOUT $FE,2, "no xxx"
PAUSE 500
SEROUT2 GPSto,Gpsbps,["$PSRF103,00,00,01,01*25",13,10] 'set ON GGA
GOTO CHECK_GGA:
GPGGA: 'start the next step....

mackrackit
- 11th July 2010, 10:38
Are your saying that timeout will not work if the expected character string OR any signal is received whithin the timeout value? I'm confused.
Yes, that is why TIMEOUT does not work with RF serial comms either. There is always noise that will appear to be a signal.
Here is a snippet from a GPS app of mine if it helps.
SERIN2 PORTB.2,16572,[WAIT("$GPGGA"),WAIT(","),DEC2 H,DEC2 M,DEC2 S,_
WAIT(","),DEC2 ND,DEC2 NM,WAIT("."),DEC3 NMD,WAIT(",N,"),_
DEC3 WD,DEC2 WM,WAIT("."),DEC3 WMD]

flotulopex
- 11th July 2010, 11:12
Thanks for this clarification - may help me a lot ;)

I will leave timeout by side then.

How would one make sure then, that, in my example, the GGA sentence has been generated in the GPS module?

Should I make a loop, timed, let's say at least 2 seconds, watch for the "$GPGGA" string anf flag it (yes/no)? But this will not work since the "WAIT" will make the program stop here!!!

In fact, my problem is, my module after being left peacefully in the drawer for more than a week returns to its default settings. Unfortunately, the RMC sentence is not generated in the module by default so I need to activate it. I've noticed, I sometimes need to generate the activation commande several times before the module will accept it. This is why I need to check if the particular sentence is activated.

mackrackit
- 11th July 2010, 14:13
I am not sure of the best way to go then.
Maybe have a routine at startup using TIMEOUT just to check for $GPGGA and if it is not found send the activation command. When $GPGGA is found the code goes to the MAIN operation.