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 CCS Technical Support

RS232 on a pin other than RC6 and RC7

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







RS232 on a pin other than RC6 and RC7
PostPosted: Wed Nov 03, 2004 8:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 03, 2004 8:39 am     Reply with quote

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







PostPosted: Wed Nov 03, 2004 8:51 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 03, 2004 9:20 am     Reply with quote

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







PostPosted: Wed Nov 03, 2004 4:52 pm     Reply with quote

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







PostPosted: Wed Nov 03, 2004 4:58 pm     Reply with quote

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







PostPosted: Wed Nov 03, 2004 5:00 pm     Reply with quote

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







PostPosted: Thu Nov 04, 2004 3:46 am     Reply with quote

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
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