|
|
View previous topic :: View next topic |
Author |
Message |
valemike Guest
|
RS232 on a pin other than RC6 and RC7 |
Posted: Wed Nov 03, 2004 8:30 am |
|
|
PIC16F876
I have a board where RC6 and RC7 are connected to a MAX232 chip. I have no problems doing printf to Hyperterminal this way.
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
However, when i take jumper wires to connect RC6 to another unused pin, say RB1, I rewrite the #use statement:
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_C7, ERRORS)
I have not even assigned set_tris() statements at this point, and left them at their default power-up input states.
Unfortunately, I cannot get my printf to work anymore. Do the above #use RS232 statements assume that RC6 and RC7 use the built-in UART of the PIC?
Thanks,
Mike |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Nov 03, 2004 8:39 am |
|
|
If the #use rs232 statement calls for the hardware UART pins then the compiler will use the hardware UART. If you call for any other pins the compiler automatically uses a software UART. With a software UART the ERRORS directive no longer works.
I think what you describe ought to work if pin C6 is left in the default input state, as long as you don't need the ERRORS functionality and your program is compatable with the processor demands of the software UART. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 03, 2004 8:51 am |
|
|
The most likely problem, is that you have interrupts enabled for something else...
The 'software' UART, relies on doing simple 'loop' timings to do the RS232. Almost any interrupt activity will cause this not to give accurate enough timings (you can with care, run at reasonable clock rates, and a low baud rate, with short interrupts occuring). If you need interrupts to be serviced without too much delay, you can make an 'encapsulated' version of putc, like:
Code: |
void no_int_putc(int8 chr) {
disable_interrupts(global);
putc(chr);
enable_interrupts(global);
}
|
Then use printf, with:
printf(no_int_putc,"Test Message");
This way the interrupts are disabled on a 'per byte' basis, giving just over 1mSec delay (at 9600bps) in the 'worst case'.
Best Wishes |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Nov 03, 2004 9:20 am |
|
|
I was thinking that when you jumpered the board,.. you no longer use the max 232 chip. Then you need the INVERT in the 232 statement.
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=16000000)
#use rs232(baud=38400,xmit=PIN_C4,INVERT,stream=DEBUG) // STDERR(same as DEBUG)
int8 time,seconds;
void main() {
fprintf(DEBUG,"Starting!!\n\r");
while (1)
{
}
}
|
A resister inline with RX is needed also. |
|
|
valemike Guest
|
|
Posted: Wed Nov 03, 2004 4:52 pm |
|
|
treitmey wrote: | I was thinking that when you jumpered the board,.. you no longer use the max 232 chip. Then you need the INVERT in the 232 statement.
A resister inline with RX is needed also. |
Treit, i connected a wire from RB1 to RC6, which connects RB1, RC6, and the MAX232 pin all together. |
|
|
valemike Guest
|
|
Posted: Wed Nov 03, 2004 4:58 pm |
|
|
Ttelmah wrote: | The most likely problem, is that you have interrupts enabled for something else...
The 'software' UART, relies on doing simple 'loop' timings to do the RS232. Almost any interrupt activity will cause this not to give accurate enough timings (you can with care, run at reasonable clock rates, and a low baud rate, with short interrupts occuring). If you need interrupts to be serviced without too much delay, you can make an 'encapsulated' version of putc, like:
|
I don't have interrupts enabled. In fact my program looks like this:
void main(void)
{
while (1)
{
printf ("Hello World\r\n");
}
...
}
As you can see, I didn't let the program run past the while(1) printf statement. So no interrupts here.
I'm not too worried now about it though. I just wanted to debug something and dump values while it was running. Since i found the problem, no need for RS232 anymore.
RS232/printf()/MAX232 is a priceless tool for debugging! Especially, when you don't want to stop the program with breakpoints. |
|
|
valemike Guest
|
|
Posted: Wed Nov 03, 2004 5:00 pm |
|
|
SherpaDoug wrote: | If the #use rs232 statement calls for the hardware UART pins then the compiler will use the hardware UART. If you call for any other pins the compiler automatically uses a software UART. With a software UART the ERRORS directive no longer works.
I think what you describe ought to work if pin C6 is left in the default input state, as long as you don't need the ERRORS functionality and your program is compatable with the processor demands of the software UART. |
I see. So if i use xmit=RC6 and rcv=RC7, then by default, CCS will use the hardware UART? |
|
|
Ttelmah Guest
|
|
Posted: Thu Nov 04, 2004 3:46 am |
|
|
valemike wrote: | SherpaDoug wrote: | If the #use rs232 statement calls for the hardware UART pins then the compiler will use the hardware UART. If you call for any other pins the compiler automatically uses a software UART. With a software UART the ERRORS directive no longer works.
I think what you describe ought to work if pin C6 is left in the default input state, as long as you don't need the ERRORS functionality and your program is compatable with the processor demands of the software UART. |
I see. So if i use xmit=RC6 and rcv=RC7, then by default, CCS will use the hardware UART? |
Yes.
Apparently though, it doesn't, if you only use one pin in a particular #use statement. This is useful, where you want to use a 'soft' UART, on the hardware pins, you can just set up two seperate streams, using the two pins, and use the soft UART.
Best Wishes |
|
|
|
|
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
|