CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

RS232 error for multiple RS232 ports on one chip

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Rainy
Guest







RS232 error for multiple RS232 ports on one chip
PostPosted: Thu Aug 28, 2008 1:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 1:24 pm     Reply with quote

The ERRORS parameter only works with the hardware UART.
The compiler ignores it for software UARTs.
Rainy
Guest







PostPosted: Thu Aug 28, 2008 1:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 1:40 pm     Reply with quote

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







PostPosted: Thu Aug 28, 2008 1:48 pm     Reply with quote

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







PostPosted: Thu Aug 28, 2008 1:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 28, 2008 2:19 pm     Reply with quote

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







PostPosted: Fri Aug 29, 2008 1:23 pm     Reply with quote

Thanks a lot, PCM programmer! I got it work following your advice.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group