![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Guest
|
How to use 2nd UART |
Posted: Tue Aug 26, 2008 5:19 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 26, 2008 5:53 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Aug 27, 2008 4:33 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 27, 2008 4:49 pm |
|
|
The CCS stream functions only accept a constant for the 'stream' value. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Aug 27, 2008 5:22 pm |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 27, 2008 5:44 pm |
|
|
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); |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Aug 27, 2008 5:59 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|