PDA

View Full Version : Handling Serial 8N2



bcd
- 29th July 2006, 13:56
I have an industrial controller I need to interface with that uses a serial interface running at 8N2.

I've had a quick look through the PBP and the midrange PIC manuals and the only way I can think of doing this is by using the 9 bit mode of the internal UART and setting it to be low for the transmit, and just ignoring it on reception.

Am I missing something obvious ??

Thanks,
Bill.

paul borgmeier
- 29th July 2006, 15:22
I think you are correct (about how to do 8N2) except the hardware UARTs are "true" meaning they idle high - therefore the stop bits need to be high. Using software, you can run true (idle high) or invereted (idle low) using serin, serout, etc.

also see this thread for a semi-related discussion

http://www.picbasic.co.uk/forum/showthread.php?t=1749

paul borgmeier
- 29th July 2006, 16:58
Thinking about it .... you can just use SERIN and SEROUT in regular 8N1 format:

Receiving - 8N2 instead of 8N1 is of no consequence since the stop bit is the same as the idle position (the extra stop bit will be ignored with no effort on your part)
.
Transmitting - you can use “DEFINE CHAR_PACING VALUE” to pause between transmissions of each byte. (Just pause the length of on bit transmission to get the second stop bit)

What baud rate do you want? (e.g., VALUE above would be 104 or more for 9600 baud.) See the PBP manual.

bcd
- 30th July 2006, 05:34
Hi Paul,

38400 is the baud rate. I like the idea of using the pacing, but I am pretty sure that the SERIN / SEROUT combos are limited to 19200 max in terms of Baud Rate. 38400 is easy with a hardware UART and a 20MHz crystal.

I think I'll grab a bit of proto board and a 16F and see if I can fool around with some code to get it working.

Thanks,
Bill

paul borgmeier
- 30th July 2006, 14:45
You had mentioned "setting it low for transmission" which is what you would do if you wanted inverted 8N2. The hardware uses true (idle high).
38400 is the baud rate. I like the idea of using the pacing, but I am pretty sure that the SERIN / SEROUT combos are limited to 19200 max in terms of Baud Rate. 38400 is easy with a hardware UART and a 20MHz crystal.
You could: DEFINE OSC 10 but use your 20 and get 38400 out of SERIN and SEROUT. IF you do, watch your other timing issues like Pause (see section 7.1 of the PBP manual).