Because the idle state of the serial line, for the mode you've selected, is high and you're driving the pin low when the PIC starts up. When the receiver sees that low it Thinks its the startbit and starts to shift in data which you aren't actually sending. That's the garbage you get. This happens BEFORE the execution of the SEROUT command which will THEN set it up properly for you.
If you, in your "startup code" set the pin you're going to use as the serial out pin high and then set it to output (as Ioannis showed) then the "line" idles at the correct state and the receiver isn't "triggered" until the SEROUT command actually exectutes.
Another (IMHO better) option is to NOT clear the TRIS bit for that particular pin.
That way it'll remain in high impedance mode until the SEROUT command actually executes - and it will set the pin to output AND set the idle state properly based on the MODE you select.
/Henrik.
Thanks a lot![]()
Roger
Great illustration here of the need to have predefined states. I had been "tossing out" the first byte of data received, now I don't need to do that. Thanks guys.
Picster
Slightly off topic, is this only true for SERIN2 / SEROUT2, and not applicable when using HSERIN / HSEROUT and the dedicated hardware /PINS on a PIC. I've always tend to use PICs with serial ports and used the excellent PIC MultiCALC tool by mister_e ( http://www.picbasic.co.uk/forum/showthread.php?t=4994 ) to give me the defines.
Depends if you use it directly on RS-232 bus or with a driver which is actually an inverter.
Bus should stay at the predefined idle state which is -12 Volts meaning that TTL logic level of the controller is at High (3 or 5 volts).
So, the answer is yes, either Serout or Hserout.
But if you drive directly the RS-232 bus, TTL should be reversed in the Serout2 setup and Hserout should only be used if there is a special setting in the PIC's UART that reverses the TTL state.
Hope this is not too complicated.
Ioannis
Bookmarks