Arduino Software Serial Tx Tri-state

Hi All,

I was wondering if its possible to put software serial pins in tri-state during the periods of no transmission? I tried the following:

/**** setup ****/
#define SerialRX 10
#define SerialTX 11
SoftwareSerial mySerial(SerialRX, SerialTX);

/***** Initialization *****/
mySerial.begin(9600);
pinMode(SerialTX, INPUT); // putting it in tri-state
digitalWrite(SerialTX, LOW);

/Main/

// Code does something ......

// Now I gotta Transmitt.....
pinMode(SerialTX, OUTPUT); // disabling tri-state
digitalWrite(SerialTX, HIGH);
mySerial.write(dataToPi, 10);
pinMode(SerialTX, INPUT);
digitalWrite(SerialTX, LOW);

.......

However, this doesn't seem to work. Any solutions?

What do you think should that be used for?

And define what "doesn't seem to work" means!

BTW, as you didn't specify your Arduino model we expect you to use an Arduino UNO.

Apologies for that. I am using Arduino Nano.

I have multiple devices sharing a UART connection in Single-Master Multi-Slave configuration.

Doesn't work means, that the data transferred is not correct. There isn't any compilation error or anything. So If during the code, I never specify SERIAL_TX as input, the data transmitted is perfect. However, if it is defined as input just once, the data transmitted becomes garbage.

I have multiple devices sharing a UART connection in Single-Master Multi-Slave configuration.

That doesn't work so easily. You would at least have to pull-up the TX line so it has a HIGH state in idle. How do you ensure that no two slaves are using the TX line at the same time? If they do you produce a short circuit.

The variable name dataToPi indicate you're communicating with a Raspberry Pi. You might fry the Raspi (3V3) pins if you connect them directly to a Nano (5V).

I have implemented addressing in the software code. Therefore, if the master wants to talk, it sends an interrupt to all the arduinos. Along with the interrupt a serial data is transmitted with the device ID. The arduinos unpack the data, if the ID matches, it responds, otherwise discards it. Therefore, no two arduinos can talk at the same time. Plus, the way the code is written, arduinos can never transmit data unless, they are polled by the Master first (Pi).

For your suggestion, if I pull-up the TX line to 5V and put the arduino in Tri-state, it should work?

I am using logic coverters so the Pi getting fried is covered :smiley:

There is a simple way to connect one Master serial port to several other "Slaves" so that there can be bi-directional communication.

Use a 5k6 resistor attached to the Master Rx to pull it to Vcc. Then connect each Slave's Tx to the Master's Rx through a diode (one for each slave) oriented so that the HIGH voltage from the Slave Rx cannot reach the Master. That way the resistor holds the Master Rx HIGH but any slave can pull it LOW via the diode.

The Master Tx can be directly connected to all the Slave Rx pins.

Then you should arrange your software so that a slave only talks when requested to do so by the master.

...R

Thanks. So I solved the issue by pulling the Master Rx to Vcc and then putting the Slave TX pins in tri-state whenever no transmission is required. I increased the baud rate of the AltSoftSerial to 57600 bps. Otherwise at 9600 bps , I had to put the delay of around 10ms right after issuing the serial write command and before putting the pin to tri-state. Thanks for all your help!!