Scottl
Joined: 21 Feb 2005 Posts: 25
|
Multiple serial ports? |
Posted: Thu Oct 18, 2007 8:44 pm |
|
|
I am using a PIC12F683 and want to relay messages received from a serial port out to another. I have setup the following for the serial ports:
#use rs232(baud=9600,parity=N,xmit=PIN_A1,rcv=PIN_A0,bits=8, STREAM=COM_A)
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A5,bits=8, STREAM=COM_B)
I have enabled #int_RA and the following code:
[code]
#int_RA
RA_isr()
{
c=fgetc(COM_A);
d=fgetc(COM_B);
if (c == 88)
{
i = c;
fprintf(COM_A, "ibm");
break;
}
if (c == 17)
{
fputc(c, COM_B);
do {
c=fgetc(COM_A);
fputc(c, COM_B);
} while (c!=0);
c=0;
d=0;
}
if (d > 0)
{
fputc(d, COM_A);
do {
d=fgetc(COM_B);
fputc(c, COM_A);
} while (d!=0);
c=0;
d=0;
}
}
[/code]
What I want to happen is if data comes in on COM_A check first bit then either pass out to COM_B or break and use later in my code. Then if the data is sent out COM_B I will receive a message on COM_B immediatelly after the last character is send out. This data will be sent back to COM_A.
Is there a better way to do this? I want to try to use something like an interrupt because I never know when the request on COM_A will be coming!
Thanks in advance,
ScottL |
|