|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
using only UART Rx |
Posted: Thu Jan 17, 2008 2:46 pm |
|
|
Hi All,
Is it possible to activate the RS232 port only with Rx pin ??
I dont need to transmit, and all other pins including Tx pin allready needed for IO.
Thanks, |
|
|
Ttelmah Guest
|
|
Posted: Thu Jan 17, 2008 3:26 pm |
|
|
Define the UART as normal, with both the TX, and RX pins.
Then create a one bit define:
#byte TXSTA=0xFAC
#bit TXEN=TXSTA.5
This is for a 18F chip. For a 16 chip, you'll need to change the TXSTA address - the data sheet has this.
In your code, near the start, simply add:
TXEN=false;
This turns off the trasmit part of the UART. Provided you don't use any transmit instructions (putc, printf etc.), no code will be generated for the 'transmit' side, the pin will become useable, and the receive will still work.
You need to do the 'two pin' define, or the compiler will generate 'software' serial code, rather than code to access the hardware UART.
Best Wishes |
|
|
evsource
Joined: 21 Nov 2006 Posts: 129
|
|
Posted: Thu Mar 05, 2009 12:50 pm |
|
|
Ttelmah wrote: | Define the UART as normal, with both the TX, and RX pins.
Then create a one bit define:
#byte TXSTA=0xFAC
#bit TXEN=TXSTA.5
This is for a 18F chip. For a 16 chip, you'll need to change the TXSTA address - the data sheet has this.
In your code, near the start, simply add:
TXEN=false;
|
I was banging my head against a wall trying to figure out why AN0 was always sitting at 5V on the pin when I had it configured for an ADC port. Turns out, since I didn't have a Tx pin defined in a #use rs232 line, it decided PIN_A0 would make a good one on its own!
I was pleased to come across this post by Ttelmah. However, using the code on a 18F2620, it still doesn't work. Example code:
Code: |
#include <18f2620.h>
#device ADC=10 // use 10 bit ADC reading
#fuses HS,WDT256,NOMCLR,NOWDT,NOPROTECT,NOBROWNOUT,BORV21,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, stream=ui, errors)
//#use rs232(baud=1200, xmit=PIN_A0, rcv=PIN_B0, stream=secondary)
#byte TXSTA=0xFAC
#bit TXEN=TXSTA.5
void main() {
TXEN=false;
setup_wdt(WDT_OFF);
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports( AN0_TO_AN4 );
set_adc_channel(0);
while(1) {
fprintf(ui,"PIN_A0: %Lx\r\n",read_adc());
delay_ms(500);
}
}
|
Commenting in and out the #use RS232 line makes PIN_A0 go from no voltage on the pin to 5V.
Any ideas? |
|
|
Ttelmah Guest
|
|
Posted: Thu Mar 05, 2009 1:09 pm |
|
|
TXEN, is to turn off the _transmit_ side of the hardware UART. Since you are using the transmit, this won't work.
Try turning off the comparator (NC_NC etc., in a setup comparators line). On some chips, the comparator wakes up enabled. Though it should not cause this, it might be having an effect.
What compiler version are you on?.
Have used the 2620, in a lot of systems, and ever seen A0, do anything it shouldn't. It may be some specific bug on a particular compiler.
Best Wishes |
|
|
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Thu Mar 05, 2009 1:17 pm |
|
|
just to complement
clear CREN just after setting TXEN, that wont let your software stuck if get some error.
regards _________________ Andre |
|
|
evsource
Joined: 21 Nov 2006 Posts: 129
|
|
Posted: Thu Mar 05, 2009 2:14 pm |
|
|
Ttelmah wrote: | TXEN, is to turn off the _transmit_ side of the hardware UART. Since you are using the transmit, this won't work.
Try turning off the comparator (NC_NC etc., in a setup comparators line). On some chips, the comparator wakes up enabled. Though it should not cause this, it might be having an effect.
What compiler version are you on?.
Have used the 2620, in a lot of systems, and ever seen A0, do anything it shouldn't. It may be some specific bug on a particular compiler.
|
Version 4.030.
I realized after I posted that this fix might not work since I have two RS232 ports defined. BTW, I'm not transmitting on the port that I'm trying to disable TX on. |
|
|
bwhiten
Joined: 26 Nov 2003 Posts: 151 Location: Grayson, GA
|
Thanks! |
Posted: Thu Jun 25, 2009 2:40 pm |
|
|
Ttelmah's support helped me as well. I have an implementation of a 18F67J11 where I needed to just monitor two separate serial paths but also needed to use the TX pins for I/O. The register addresses were different for this device but not hard to find in the data sheet. Now the monitoring works great with no interference from the HW TX on the pins.
Thanks. |
|
|
|
|
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
|