PDA

View Full Version : 3 serial ports on pic with independent baud rate and parity



pedja089
- 12th August 2011, 18:51
I need 4 serial port on pic.
1 of them if for PC, so baud rate and parity isn't important.
For other 3 ports
1. must be 2400,8,E,1 - for now work fine with serin2 and define 9bits.
2. must be 9600,8,N,1 - For that I also try to use serin2, but mode is 84. And i had no luck... Modem doesn't recognise commands. If I remove define 9bit it works.
3. must be user define, baud rate 2400 or 9600, with or without parity.
I'm using PIC18F87J50, there are 2 hardvare usart.
3. port is problem... If I don't have 3. port then I would use, serin/out for port 1. And hserin/out for other ports...
Does anyone have an idea how to do this?

mackrackit
- 12th August 2011, 19:41
Do not use DEFINEs for the hardware ports, work the registers directly. Then use SERIN2/SEROUT2 as normal.

pedja089
- 12th August 2011, 19:53
Thats ok, if i only chande BR, but what with parity?

mackrackit
- 12th August 2011, 20:00
From section 20.2 of the data sheet


The EUSART transmits and receives the LSb first. The
EUSART’s transmitter and receiver are functionally
independent but use the same data format and baud
rate. The Baud Rate Generator produces a clock, either
x16 or x64 of the bit shift rate, depending on the BRGH
and BRG16 bits (TXSTAx<2> and BAUDCONx<3>).
Parity is not supported by the hardware but can be
implemented in software and stored as the 9th data bit.

pedja089
- 12th August 2011, 20:19
Yes I know that...
But I think you didn't understand me...
Let me try to explain again...
Let say that I use define ser2 9 bit, define parity even, and use that for 1. port. For 2. port to use HSERIN,
But then if user want to enable parity on 3. port there is problem...
If I use HSERIN2 I must put DEFINE HSER_BITS 9 that option should be enabled from PC.
So I can't just put If useparity=1 then define hser 9bits etc...
I was thinking if there is define ser2 9 bit, and use mode for 8 bit that it should send 8 bit, but it send 9 bit...<small>
</small>

mackrackit
- 12th August 2011, 20:30
I was thinking if there is define ser2 9 bit, and use mode for 8 bit that it should send 8 bit, but it send 9 bit...

Look in the PBP manual to see how to use the second hardware port.

pedja089
- 12th August 2011, 20:35
Thank you.
Think I'll have something...