View previous topic :: View next topic |
Author |
Message |
Maverick72
Joined: 01 Feb 2006 Posts: 5
|
2 serial rs-232 port at the same time |
Posted: Wed Feb 08, 2006 8:44 am |
|
|
Hi,
I'm using a PIC18F1320 in my design and want to use Hardware and software USART at the same time. The hardware USART is connected to a PC and the Software USART is connected to a Dallas one wire line driver.
I saw in the CCS manual that you can use #use rs232 command to set the RS232 ports. Does anybody have a source code to use the built in USART and use portB to drive a software USART at the same time.
Thank's |
|
|
Maverick72
Joined: 01 Feb 2006 Posts: 5
|
|
Posted: Wed Feb 08, 2006 8:45 am |
|
|
I forgot to say that the hardware USART connects to PC trough a MAX232 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 09, 2006 12:38 pm |
|
|
Here is some simple code to get you started.
Code: | #include <18F1320.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4, ERRORS, stream=HW_UART)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B2, stream=SOFT_UART)
void main(void)
{
char c;
setup_adc_ports(NO_ANALOGS);
fprintf(HW_UART, "Start\n\r"); // Send to hardware UART
c = fgetc(HW_UART); // Get char from hardware UART
fputc(c, SOFT_UART); // Transmit it with software UART
while(1); // Don't let PIC go to sleep
} |
|
|
|
Maverick72
Joined: 01 Feb 2006 Posts: 5
|
|
Posted: Thu Feb 09, 2006 1:53 pm |
|
|
Thank's
I already figured it out yesterday. At first I tried with the RX pin on port A and the TX pin on port B. Could that have been the reason why it didn't work ? |
|
|
Maverick72
Joined: 01 Feb 2006 Posts: 5
|
|
Posted: Thu Feb 09, 2006 1:54 pm |
|
|
Forgot to say that i configured those pin for the software UART |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 09, 2006 2:24 pm |
|
|
I can't know for sure, unless you specify the exact pin.
The pins on Port A can have many functions. They can
be analog, or LVDIN, MLCR, oscillator, or digital i/o.
Also RA5 is input only, and RA4 is open-drain.
(it can't drive high. It requires a pullup resistor)
You must have a digital output pin for Tx and a digital
input pin for Rx.
So there could be many reasons why your soft UART
didn't work on Port A.
Remember, the Microchip designers try to cram as many
features as possible onto each pin and you have to choose
a pin that will work, and you have to configure it for digital i/o. |
|
|
|