View previous topic :: View next topic |
Author |
Message |
Rainy Guest
|
RS232 error for multiple RS232 ports on one chip |
Posted: Thu Aug 28, 2008 1:20 pm |
|
|
Hello everyone,
I'm using PIC18F452 for my project. I have 1 hardware UART and 2 sw UARTS in one chip. I'm just wondering if I want to use the "error" option, how can I distinguish the error for different streams?
If I declare like this, I found that the latter one is the one taking effect, the first one seems to be overwriten by the latter one.
Thanks a lot for any help!
Code: | #use rs232(baud=9600,parity=N,xmit=PIN_B4,rcv=PIN_B2,stream=portA,bits=8, errors, timeout=RS232_TIMEOUT)
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B1,stream=portB,bits=8, errors, timeout=RS232_TIMEOUT) |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 28, 2008 1:24 pm |
|
|
The ERRORS parameter only works with the hardware UART.
The compiler ignores it for software UARTs. |
|
|
Rainy Guest
|
|
Posted: Thu Aug 28, 2008 1:29 pm |
|
|
Thanks for your reply. So is there any solution for a timeout on the S/W UART? Acutally in my test, seems it works for the latter UART, when I unplug the RS232 device from this port, it can get out. Yet for the first declared RS232 port, if I unplug the device, it just hung there. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 28, 2008 1:40 pm |
|
|
Now I see what you're talking about. My comment about ERRORS
referred to the ability to automatically clear a receiver overrun error.
You're referring to this feature of the #use rs232() library code:
Quote: | TIMEOUT=X
To set the time getc() waits for a byte in
milliseconds. If no character comes in within
this time the RS232_ERRORS is set to 0 as
well as the return value form getc(). This works
for both UART and non-UART ports. |
|
|
|
Rainy Guest
|
|
Posted: Thu Aug 28, 2008 1:48 pm |
|
|
Yes you are right. That's what I'm trying to say. Sorry about the bad expression.
So any solution for that? Thanks for your prompt response! |
|
|
Rainy Guest
|
|
Posted: Thu Aug 28, 2008 1:52 pm |
|
|
I tried to use a loop like this
Code: | {
...
code
...
} while (RS232_ERRORS); |
but only works for one port.
Maybe I'll have to put my own timer there for timeout. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 28, 2008 2:19 pm |
|
|
CCS has an example code for the timed_getc() function here:
Quote: | c:\program files\picc\examples\ex_tgetc.c |
You would have to modify it to work with a particular stream.
Change the getc() to fgetc(), and specify the stream in the kbhit()
function. I notice the sample code uses a software delay loop.
That could cause a problem with a software UART. It adds an
delay between the detection of the start bit and the reception of
the other bits. It might reduce the reliability of the software
UART. |
|
|
Rainy Guest
|
|
Posted: Fri Aug 29, 2008 1:23 pm |
|
|
Thanks a lot, PCM programmer! I got it work following your advice. |
|
|
|