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

Turning on and off RS-232 Transmit Pin with #use

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



Joined: 18 Feb 2004
Posts: 12

View user's profile Send private message Send e-mail

Turning on and off RS-232 Transmit Pin with #use
PostPosted: Fri Mar 05, 2004 6:43 pm     Reply with quote

I have a big problem that hopefuly someone here can help with. I am using the 3.185 compiler targetting a PIC18F452. In the main header file for my application, I have the following line:
Code:

#use   rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


My understanding is that this line will then configure the USART on the PIC18F452 to send and receive serial data. That part works, and I can communicate. I have a Cygnal CP2101 USB-to-UART bridge connected to the TX and RX pins to allow USB communications from a PC to be received by the micro as RS-232 data.

The CP2101 is supposed to be powered from the USB bus only. I've found that the TX pin being default HIGH will "backpower" the device when the USB cable is removed. I am trying to make a software work around for this.

I think I need to disable the TX pin and force it to a TTL LOW when I am not using it, yet still leave the RX pin active. I think doing this will solve my powering problem and let the CP2101 fully shut down. I still need to be able to enable the TX pin when needed.

I have tried using some assembly code to shut the TX function down in main() and then re-enable it in my comms routines, but that seems to have no affect. Nor does simply trying to set the signal low, for the obvious reason that the pin is assigned and controlled by the USART.

This is also my first C coding for PICs, and I am finding some of the features of this compiler not fully explained. I tried to add the following #use statement in the header file to hopefully not configure a Transmit pin:
Code:

#use   rs232(baud=19200,parity=N,rcv=PIN_C7,bits=8)


The other #use statement where TX is initialized is then placed in the comms file. My hope was that the compiler would use the local #use for all routines in that particular file, and the one in the header file for all other files. That doesn't seem to be the case, so I need ideas. I have searched this forum, but haven't found anything that directly addresses my problem. I am curious to how to overide the #use statement in the header to disable the TX line.

Any help would be appreciated.
Ttelmah
Guest







Re: Turning on and off RS-232 Transmit Pin with #use
PostPosted: Sat Mar 06, 2004 3:31 am     Reply with quote

plehman wrote:
I have a big problem that hopefuly someone here can help with. I am using the 3.185 compiler targetting a PIC18F452. In the main header file for my application, I have the following line:
Code:

#use   rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


My understanding is that this line will then configure the USART on the PIC18F452 to send and receive serial data. That part works, and I can communicate. I have a Cygnal CP2101 USB-to-UART bridge connected to the TX and RX pins to allow USB communications from a PC to be received by the micro as RS-232 data.

The CP2101 is supposed to be powered from the USB bus only. I've found that the TX pin being default HIGH will "backpower" the device when the USB cable is removed. I am trying to make a software work around for this.

I think I need to disable the TX pin and force it to a TTL LOW when I am not using it, yet still leave the RX pin active. I think doing this will solve my powering problem and let the CP2101 fully shut down. I still need to be able to enable the TX pin when needed.

I have tried using some assembly code to shut the TX function down in main() and then re-enable it in my comms routines, but that seems to have no affect. Nor does simply trying to set the signal low, for the obvious reason that the pin is assigned and controlled by the USART.

This is also my first C coding for PICs, and I am finding some of the features of this compiler not fully explained. I tried to add the following #use statement in the header file to hopefully not configure a Transmit pin:
Code:

#use   rs232(baud=19200,parity=N,rcv=PIN_C7,bits=8)


The other #use statement where TX is initialized is then placed in the comms file. My hope was that the compiler would use the local #use for all routines in that particular file, and the one in the header file for all other files. That doesn't seem to be the case, so I need ideas. I have searched this forum, but haven't found anything that directly addresses my problem. I am curious to how to overide the #use statement in the header to disable the TX line.

Any help would be appreciated.

It is worth undertsanding, that 99.9% of the things that you may feel need assembler, can be done in C using the #bit, and #byte directives. I'd suspect that the #use directives are switching as you expect (the compiler uses the last #use met), _but_, selecting to receive only, does not 'turn off' the transmitter side of the UART if this is allready enabled.
Now it would appear that what you actually need to do, is just to ensure that the serial transmit line is pulled low, when you are not using the transmit ability. This should be achievable like this:
Code:


//add this defintion somewhere at the top of your code
#bit TXEN=0xFAC.5

#define tx_break() TXEN=0;\
   output_low(PIN_C6)

#define tx_on(); TXEN=1


Then when you want the transmitter disabled, simply use 'tx_break();', and when you want the transmitter back on, use 'tx_on();'.
You should ensure that you delay for one byte time after re-enabling the transmitter (depending on how the system at the other end responds to seeing a 'break' transmitted, this allows it's UART to shift out the remains of the character, and start looking for data).

Best Wishes
plehman



Joined: 18 Feb 2004
Posts: 12

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 06, 2004 7:26 am     Reply with quote

Thanks for responding.

It tried what you said, by adding those lines, and putting a tx_on() before my transmission routine and tx_break() at the end of the routine as well as in main(), but it didn't work. That leaves me with two thoughts:

1) I'm still incorrectly using the #use rs232 statements (there is only one now in the default .h file). I wonder if everytime I jump to another file or routine, is it re-enabled, or is #use coded to run at startup only?

2) That Microchip designed the 18F452's USART to take control and keep control of BOTH pins when even only 1 is used, so turning the transmitter enable on and off doesn't release it from the USART's control such that TRISing the port control register and setting the bit would have any affect.

You are right about the byte delay though. Thanks.
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