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

How to use 2nd UART

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








How to use 2nd UART
PostPosted: Tue Aug 26, 2008 5:19 pm     Reply with quote

How do you switch between UARTs for those devices that have 2 UARTs?

For example, putc(c), or getc(), how do you tell the code which UART to use?

Also, how do you handle the interrupt service routine? Is there an ISR for each UART?

The manual is silent on all this.

Steve
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 26, 2008 5:53 pm     Reply with quote

1. Specify a "stream" in each #use rs232() statement.

2. Then use fputc, fgetc, fprintf, etc., and specify the stream to be used.
See the CCS manual for descriptions of these functions.

3. Use #INT_RDA for the 1st UART. Use #INT_RDA2 for the 2nd UART.
See the .H file for your PIC for a list of #INT_ directives. Look near the
end of the file.
Guest








PostPosted: Wed Aug 27, 2008 4:33 pm     Reply with quote

Ahhhh! I see.

Can you tell me why the compiler error for "com2" in the set_uart_speed call?

#use rs232(UART1,baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors,stream=com1)
#use rs232(UART2,baud=9600,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,errors,stream=com2)
...
set_uart_speed( 1200,(which_port==com1) ? com1:com2);

But yet, this line compiles:

set_uart_speed( 1200, com2);

It didn't like using "which_port" as an argument, even though it's set like this:

which_port = com1;

It says it needs to be a constant.

Steve
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 27, 2008 4:49 pm     Reply with quote

The CCS stream functions only accept a constant for the 'stream' value.
Guest








PostPosted: Wed Aug 27, 2008 5:22 pm     Reply with quote

I got that. But the two lines seems equivalent to me. In any case, I modified my routine to the following. The same #use rs232 defines in my previous post are still there and unchanged.
Code:

if ( which_port == com1 ) {
   set_uart_speed(baud*10, com1);
 }
 else if ( which_port == com2 ) {
   set_uart_speed(baud*10, com2);
 }

I now get a compiler error for both "com1" and "com2" in the set_uart_speed calls saying "A numeric expression must appear here." So what's it complaining about now!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 27, 2008 5:44 pm     Reply with quote

Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

In the section on set_uart_speed(), it says:
Quote:
Syntax: set_uart_speed (baud, [stream, clock])

Parameters: baud is a constant 100-115200 representing the number of bits per second.


In your code below, you are using a variable for the baud rate:
Quote:
set_uart_speed(baud*10, com1);
Guest








PostPosted: Wed Aug 27, 2008 5:59 pm     Reply with quote

Ok, I screwed that up. But the compiler was flagging "com1" and "com2" as the error, so I wasn't looking at baud.

Thanks for your help.
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