View previous topic :: View next topic |
Author |
Message |
Max Peelman Guest
|
Enabling/Disabling Hardware USART on the fly? |
Posted: Thu Feb 07, 2002 1:20 pm |
|
|
I have an application with a PIC16F877 acting as a Master communicating to four PIC16F628 Slaves using the hardware USART of the Slaves with a hard-wired /Slave Select output from the Master to each Slave. Is there a way to disable the Transmit pin of each Slave that is not selected so that the Tx line is not held HIGH and is available only to the desired Slave?
Right now I can communicate between the Master and one Slave but when I connect another Slave the Master does not receive the data transmitted by the selected Slave. I have verified that the selected Slave is transmitting data but the LOW transitions are not LOW enough for the Master to recognize.
Any suggestions would be appreciated!
___________________________
This message was ported from CCS's old forum
Original Post ID: 2466 |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
Re: Enabling/Disabling Hardware USART on the fly? |
Posted: Fri Feb 08, 2002 4:36 am |
|
|
Did you try FLOAT_HIGH in the options list of #USE RS232? This will give you the equivalent of open collector outputs which with an appropriate pull up will float up.This will stop the short circuit between one slave driving high and another slave driving low. Any slave going low will be able to pull down against the resistor any slave going high will floatup providing no slave is driving low. I know you are using the hardware USART so maybe this option doesn't apply so you will have to TRIS the transmit pin to input after you check the Tx outbuff is empty and re TRIS the TX pin to output prior to sending a byte.
___________________________
This message was ported from CCS's old forum
Original Post ID: 2488 |
|
|
Max Peelman Guest
|
Re: Enabling/Disabling Hardware USART on the fly? |
Posted: Fri Feb 08, 2002 7:11 am |
|
|
:=Did you try FLOAT_HIGH in the options list of #USE RS232?
Thanks for the suggestions. I tried FLOAT_HIGH but like you said it is not allowed for the hardware USART. I have tried various combinations of enabling/disabling the USART (using SPEN and TXEN) and setting/clearing the TRIS for the Tx pin but all I succeed in doing is keeping the Tx pin LOW at all times except when data is being transmitted. When data is being transmitted I see the bit pulses on my 'scope but they are pulses HIGH with the line normally LOW and the HIGH level is very small (it really looks like the pulses are charging a cap by the looks of the transitions).
I should mention that with these experiments I only have one Slave connected to the Master, with a 330 Ohm resistor in series to the Slave pin and another 330 Ohm resistor in series to the Master pin. I don't see any way the pin could be held LOW externally.
___________________________
This message was ported from CCS's old forum
Original Post ID: 2495 |
|
|
John Purbrick Guest
|
Re: Enabling/Disabling Hardware USART on the fly? |
Posted: Sun Feb 10, 2002 9:21 pm |
|
|
One quick 'n dirty way to deal with this is to put a diode in series with each TX pin, oriented cathode (banded end) toward the PIC chip. Tie all the anodes together to form your transmission line, and add one resistor--say 2.2K--to Vcc adjacent to the processor which receives the data. What you'll have is a "wire AND" connection, where the line is only high if all the TX pins are high, and low if any one (or more, so be careful!) is low. The RX pins can all be tied together.
The alternative would seem to involve each chip watching its transmissions, and only allowing the TX pin out of high-impedance state when it actually has something to transmit. This is perfectly possible but you have to get into the workings of the PIC's UART to do it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 2528 |
|
|
JimJ Guest
|
Re: Enabling/Disabling Hardware USART on the fly? |
Posted: Tue Feb 12, 2002 1:44 pm |
|
|
:=I have an application with a PIC16F877 acting as a Master communicating to four PIC16F628 Slaves using the hardware USART of the Slaves with a hard-wired /Slave Select output from the Master to each Slave. Is there a way to disable the Transmit pin of each Slave that is not selected so that the Tx line is not held HIGH and is available only to the desired Slave?
:=Right now I can communicate between the Master and one Slave but when I connect another Slave the Master does not receive the data transmitted by the selected Slave. I have verified that the selected Slave is transmitting data but the LOW transitions are not LOW enough for the Master to recognize.
:=Any suggestions would be appreciated!
My project is Single Master/Multiple Slave using the 9-bit command mode with the F877. I had trouble tri-stating the slave UART TX pins appropriately. The following works for me...
// ---
// Setup
// TRISC:
// C6 = input: PIC UART output is tri-stated in TRIS and enabled/disabled via TXSTA.TXEN
// C7 = input: PIC UART input
SET_TRIS_C(0b11......);
UART_TXSTA_TXEN = 0; // Setup: turn UART transmitter OFF to tristate TX output.
Then, during operation....
UART_TXSTA_TXEN = 1; // Before transmitting.
UART_TXSTA_TXEN = 0; // After transmission is COMPLETE.
// Leave time for the UART transmit register to empty.
___________________________
This message was ported from CCS's old forum
Original Post ID: 2557 |
|
|
dgi
Joined: 07 Jan 2004 Posts: 11 Location: Philadelphia, USA
|
Re: Enabling/Disabling Hardware USART on the fly? |
Posted: Wed Sep 20, 2006 11:01 am |
|
|
JimJ wrote: | :=I have an application with a PIC16F877 acting as a
My project is Single Master/Multiple Slave using the 9-bit command mode with the F877. I had trouble tri-stating the slave UART TX pins appropriately. The following works for me...
|
I am using JimJ's approach after finding that CCS compiler does not support the FLOAT_HIGH option when using the hardware UART.
I am using the PIC16F88. Here is how I implemented open-collector uart communication:
Code: |
#use rs232(baud=19200, xmit=PIN_B5, rcv=PIN_B2)
#BIT TXEN = 0x98.5 // enables output. Used for disabling/tristating output pin.
void DriveTx()
{ TXEN = 1; }
void TristateTx()
{ TXEN = 0; }
void open_collector_tx(char outChar)
{
DriveTx();
putc(outChar);
delay_us(500);
TristateTx();
}
//and then, in main()
set_tris_b(0x25); // leave it that way for the whole program
printf(open_collector_tx, "wake up %d\n\r", reset_count);
|
|
|
|
funmix
Joined: 27 Mar 2007 Posts: 33
|
|
Posted: Wed Apr 25, 2007 6:28 am |
|
|
To JimJ
Do you mind to share your working code? communication between multiple slaves via USART.
Appreciate if you are sharing |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Apr 25, 2007 6:37 am |
|
|
funmix wrote: | To JimJ
Do you mind to share your working code? communication between multiple slaves via USART. | JimJ signed in as a guest 5 years ago, small chance he is still monitoring this forum.
I suggest you search this forum for RS485. RS485 is very similar to RS232 but as a multi-drop connection it is specifically designed for talking to multiple slaves. |
|
|
funmix
Joined: 27 Mar 2007 Posts: 33
|
|
Posted: Wed Apr 25, 2007 6:50 am |
|
|
Ya..I am going to design simple 485 protocol
<start><node addr><length><data><checksum>
Do you have sample code that i can refer to design the 485 protocol?
I have gone through the rs485.c driver, but i no idea how to use all the function in rs485.
Master: 18F4520
Slave: 18F4520 x 5
Thanks |
|
|
Oli Guest
|
another way |
Posted: Thu Jul 05, 2007 9:52 am |
|
|
My way is to use:
hope this helps someone |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon Nov 22, 2010 7:54 am |
|
|
.... instead of trying to adapt a point to point protocol to handle multiple slaves... why not work with the system as it is?
you have one master pic and 4 slaves...
use a "ring" network (i know, rings = "no-no", i know)
use an identifier byte preciding data for each slave.
if the identifier is not the one for the slave.. pass data on to next pick..
no extra hardware... or strange protocols...
... my 2 cents.. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|