View previous topic :: View next topic |
Author |
Message |
FMOpt2000
Joined: 10 Jan 2008 Posts: 17
|
RS232 pin changing at runtime |
Posted: Thu Nov 17, 2011 1:52 am |
|
|
I think this is a stupid question, but I desire to be sure before
change the PIC in the design because it will involve a delay...
I'm working on a PIC18F4525.
I was using the RS232.. but now it's necessary use two rs232 channel.
But I must use it not at the same time.
So is there a way to change only the pins of RS232 channel at runtime?
Thx in advance. |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Nov 17, 2011 2:54 am |
|
|
The PIC18F4525 has one hardware uart which can only work through one pair of pins, RC6 & RC7. You can't change the hardware.
You can have two serial channels, one hardware, one software, or both software. Configure them with two #use rs232() lines. There are loads of threads here about that.
Many people end probably up with two software serials without knowing it, and even a software one when they thought they were using the hardware.
Software serial channels are slow compared hardware, are blocking on receive, cannot receive unless your code is waiting for characters, are not true full duplex - they cannot receive and transmit at the same time - but they are very flexible - can work with any IO pins and do things like enables and other useful stuff. They are fine for transmit only and for half duplex applications and can be used for many protocol uses (where transmission and reception are carefully timed and in a predictable order. I've had MODBUS working over a sw serial port).
So, if you want to run one serial port most of the time and occasionally send something over another, or something similar then yes, it'll work fine. If you want full duplex fully buffered comms on two channels then you'll need two hardware UARTs.
RF Developer |
|
|
FMOpt2000
Joined: 10 Jan 2008 Posts: 17
|
|
Posted: Thu Nov 17, 2011 4:13 am |
|
|
Thx!
I found the software serial port, but your notes about slow and blocked connection lead me to a different solution.
I will introduce a DPDT to swap the connection outside the uC with a use of one pin.
I can't do better than that, or I need to change the uC.
Bye
Franco |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Thu Nov 17, 2011 4:40 am |
|
|
Remember a second hardware port, does not need to be in the processor. Phillips do some little I2C UARTs. Also you could multiplex the I/O, using a logic gate rather than a switch. Whatever method you use though, remember that the RX line coming into the PIC needs to be biased high when not driven, including the moment the switch changes, and the TX lines into the circuitry 'beyond' the switch, also needs to be biased high when not driven.
Best Wishes |
|
|
|