Inverted mode should idle low.
True mode should idle high.
This is really simple to test. Try this;
Code:
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.
Bookmarks