Single-wire Serial in T3.5

choochoo22

Active member
I am considering two new types of functionality for an existing project. Both require using serial communications in both directions over a single wire (pin). I need help in setting this up.

In one case serial3 needs to be either a rx or tx port using pin 7, the direction would be determined during setup() and would not change throughout the run. Apparently it's not as simple as: Serial3.setTX(7), so how is this done?

In the other case serial2 needs to be bi-directional using pin 10. Presumably the solution to the previous case would show how to set the direction for the same pin but are there any special considerations changing direction dynamically, like requiring a delay after a change perhaps? I believe I can handle when to switch.
 
I am considering two new types of functionality for an existing project. Both require using serial communications in both directions over a single wire (pin). I need help in setting this up.

In one case serial3 needs to be either a rx or tx port using pin 7, the direction would be determined during setup() and would not change throughout the run. Apparently it's not as simple as: Serial3.setTX(7), so how is this done?

In the other case serial2 needs to be bi-directional using pin 10. Presumably the solution to the previous case would show how to set the direction for the same pin but are there any special considerations changing direction dynamically, like requiring a delay after a change perhaps? I believe I can handle when to switch.

I don't think you can simply assign pins of a HardwareSerial UART via a high-level API as you suggest. I searched the forum and found this message which may be relevant. It involves writing to configuration registers of the UART peripheral.

https://forum.pjrc.com/threads/6290...-communication?p=251894&viewfull=1#post251894

EDIT: You might also be able to do what you want with one of the SoftwareSerial libraries, but I don't see a 1-wire mode mentioned anywhere.
 
You can try: Serial3.begin(1000000, SERIAL_8N1_HALF_DUPLEX);

Or whatever your baud rate is...

The code sets up the port to work in half duplex mode, which is to the TX pin. It normally stays in RX mode unless you try to output to the TX pin
Serial7.write(0);

At which point it switched to output mode, it then starts the output, and when the code in the isr detects that there are no more bytes to be output and the last output has fully been sent, it then switches back to RX mode
 
Thanks,

So half duplex only works on the tx pin? I also need to set the port inverted like this:
Code:
 sbus2.begin(100000, SERIAL_8E1_RXINV_TXINV);
Would that need to be done in a separate statement then, or can they be combined like this?
Code:
sbus2.begin(100000, SERIAL_8E1_HALF_DUPLEX, SERIAL_8E1_RXINV_TXINV);  
Or this:   sbus2.begin(100000, SERIAL_8E1_RXINV_TXINV, HALF_DUPLEX);
 
They are mostly bits defined in the begin…
So just take your current one and | with I think SERIAL_HALF_DUPLEX

edit: like sbus2.begin(100000, SERIAL_8E1_RXINV_TXINV | SERIAL_HALF_DUPLEX);
 
Last edited:
Back
Top