PDA

View Full Version : SERIN SERIN2 Timeout



markedwards
- 22nd June 2005, 21:32
I need someone help getting Serin timeout to work.
If there is no data on PORTB.1 (pin = 0V) after a delay I need to jump out of Serin. I wait for "A" sync and store the next byte M.
My Serin works until data stops then hangs forever.
My Serin2 hangs always.

Test1:
Pause 110
SerIn PORTB.1,T2400,["A"],M ' Works until data stops then hangs
'serin2 PORTB.1,t2400,2000,Test2,[wait("A"),M] ' hangs
SerOut SO,T2400,[I,line2,#j," ",#M]
TOGGLE PORTB.4
GOTO Test1
Test2:
SerOut SO,T2400,[I,line2,#j," "]
TOGGLE PORTB.4
GOTO Test1

Melanie
- 23rd June 2005, 06:52
This has been covered many times. As long as the input pin is toggling (even just with noise), the timeout will keep being reset. Also, I cannot recall which (but you can easily test this), but if the input is in the wrong state when at idle, it won't time out either. You can force the correct idle state through additional hardware, or by software.

I remember posting this over a year ago (although I can't seem to find it now) as an example to a Hardware solution...

markedwards
- 23rd June 2005, 14:56
From what I read the serin & serin2 will not timeout if the input pin is high or toggling.
My data line is normally low and no noise that I can see on a scope.
I only need to transfer a byte or 2 of data and I am using an "A" to sync.
I have attempted T2400, N2400, OT2400, ON2400. I have tried both serin & serin2.

SerIn PORTB.1,T2400,["A"],M ' Works until data stops then hangs

'serin2 PORTB.1,t2400,2000,Test2,[wait("A"),M] ' hangs

I can't fit external gates, so I need a software solution. Right now I can only use the WDT to recover.

Am I mis-understanding Serin?
Any recommendations?

Thanks

Melanie
- 23rd June 2005, 17:06
But isn't the 'idle' state different whether you are running TRUE or INVERTED mode?

If you physically short the line low does it stop hanging?

If you are communicating between two PICs you can always program the sender to drag it's output to the idle state on completion of transmission.

Bruce
- 23rd June 2005, 18:03
Inverted mode should idle low.
True mode should idle high.

This is really simple to test. Try this;


N9600 CON 16468 ' 9600 bps inverted (idle should be low)
Timeout CON 1000
X VAR BYTE

Main:
serin2 portb.0,16468, Timeout,Label,[wait("A"),X]
toggle 2 ' Toggle LED on RB2 if ASCII A & byte in X received
pause 1000
goto Main

Label:
toggle 1 ' Toggle LED on RB1 (if input pin is held at 0 >1000mS)
goto Main ' Hold the input pin at logic 1 to see what happens.

END


If the device sending serial data to the PIC is keeping the pin low during idle periods, and you're using true mode with SERIN or SERIN2, then the timeout & label option will not work.

The active or "not idle" logic state on the serial input pin causes the timeout period to continually be reset, and this causes it to hang forever. This will always happen if random noise or the wrong idle logic is on the serial input pin.


SerIn PORTB.1,T2400,["A"],M ' Works until data stops then hangs
This will always hang when data stops. You're instructing the PIC to wait for the ASCII A character, then place the next byte in the M variable. If the wait condition is never met, the PIC will sit & spin waiting for it.

However, as shown above, you'll need to make sure the device sending data to the PIC is returning the PIC serial input pin to the idle logic state during idle periods, and the communications line is noise free. Otherwise the timeout and label options won't work either.

markedwards
- 23rd June 2005, 18:59
Thanks a million! Idling the Serin pin high fixes the hang.
I think that will fix my problem. It's not a problem, It's a new feature!
If communications line is broken the WDT will reset the system.