| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			picj1984
 
 
  Joined: 01 Mar 2010 Posts: 74
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| reassign Tx on #use rs232 as general purpose IO? [SOLVED] | 
			 
			
				 Posted: Tue Apr 17, 2018 1:22 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hello,
 
 
I'm not using the TX pin on my UART module.  Can I reassign that for general IO usage?   Right now I'm just trying to do the output_low() function but it's just always staying high.  
 
 
Joel
  Last edited by picj1984 on Fri May 04, 2018 3:40 pm; edited 1 time in total | 
			 
		  | 
	
	
		  | 
	
	
		
			temtronic
 
 
  Joined: 01 Jul 2010 Posts: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 17, 2018 1:47 pm     | 
				     | 
			 
			
				
  | 
			 
			
				yes, you should be able to, but you need to post which PIC and compiler version , so that others can test to confirm .
 
It could be a simple premade function or you may have to code yourself, that's why compiler version is nice to know. | 
			 
		  | 
	
	
		  | 
	
	
		
			picj1984
 
 
  Joined: 01 Mar 2010 Posts: 74
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Apr 17, 2018 2:28 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | temtronic wrote: | 	 		  yes, you should be able to, but you need to post which PIC and compiler version , so that others can test to confirm .
 
It could be a simple premade function or you may have to code yourself, that's why compiler version is nice to know. | 	  
 
 
oops sorry about that.  It's a PIC16F1825 and I'm using PCM Compiler V4.140. | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Apr 18, 2018 12:41 am     | 
				     | 
			 
			
				
  | 
			 
			
				You have to do a little bit more fiddling. Thing is that for the code to use the hardware UART it has to be told to use _both_ pins. This then leaves the TX pni being driven by the UART. So the key is to turn this off:
 
 	  | Code: | 	 		  
 
//Processor include
 
//fuses
 
//clock declaration
 
 
#use RS232(UART1, BAUD=9600, ERRORS)
 
//Standard UART enable on the default hardware pins
 
 
//Then
 
#BIT TXEN=getenv("BIT:TXEN")
 
//This now gives us access to the UART TXEN bit
 
 
void main(void)
 
{
 
    TXEN=FALSE; //Turn off the UART transmit
 
    //You can now read and write the TX pin normally
 
 
   while(TRUE)
 
      ;
 
}
 
 | 	  
 
 
As you can see it is very easy. All you do is enable the UART normally, and then turn off the transmit 'side' of the hardware. | 
			 
		  | 
	
	
		  | 
	
	
		
			picj1984
 
 
  Joined: 01 Mar 2010 Posts: 74
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri May 04, 2018 3:41 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Ttelmah wrote: | 	 		  You have to do a little bit more fiddling. Thing is that for the code to use the hardware UART it has to be told to use _both_ pins. This then leaves the TX pni being driven by the UART. So the key is to turn this off:
 
 	  | Code: | 	 		  
 
//Processor include
 
//fuses
 
//clock declaration
 
 
#use RS232(UART1, BAUD=9600, ERRORS)
 
//Standard UART enable on the default hardware pins
 
 
//Then
 
#BIT TXEN=getenv("BIT:TXEN")
 
//This now gives us access to the UART TXEN bit
 
 
void main(void)
 
{
 
    TXEN=FALSE; //Turn off the UART transmit
 
    //You can now read and write the TX pin normally
 
 
   while(TRUE)
 
      ;
 
}
 
 | 	  
 
 
As you can see it is very easy. All you do is enable the UART normally, and then turn off the transmit 'side' of the hardware. | 	  
 
 
Just realized I never came back to say "thanks!" this is working for me now   | 
			 
		  | 
	
	
		  | 
	
	
		
			gjs_rsdi
 
 
  Joined: 06 Feb 2006 Posts: 476 Location: Bali 
			
			 
			 
			 
			
			
			
			
			
			
  
		  | 
		
			
				| rs232 on/off | 
			 
			
				 Posted: Mon Nov 28, 2022 5:09 am     | 
				     | 
			 
			
				
  | 
			 
			
				I know this topic is very old but I want to thank you Ttelmah for explaining how to enable/disable the TX pin
 
 
Best wishes
 
Joe | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Nov 28, 2022 8:04 am     | 
				     | 
			 
			
				
  | 
			 
			
				Well done that you found this.    
 
 
99% of things like this have been answered here, which is why using the
 
search is such a powerful tool.
 
For some answers things have later 'evolved'. So (for example) there are
 
threads a few years ago on how to manually set ANSEL, which have now
 
been made redundant with CCS adding this to set_adc_ports). However
 
most of the answers still apply as they did when originally made.
 
 
Glad you have it doing what you want. | 
			 
		  | 
	
	
		  | 
	
	
		
			gjs_rsdi
 
 
  Joined: 06 Feb 2006 Posts: 476 Location: Bali 
			
			 
			 
			 
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Nov 28, 2022 9:21 am     | 
				     | 
			 
			
				
  | 
			 
			
				Definitely the forum search is one of the best tools available.
 
You spend some time, but you save much much more    
 
 
Best wishes
 
Joe | 
			 
		  | 
	
	
		  | 
	
	
		 |