Half-duplex UART over a single wire

michcfr
Posts: 30
Joined: Mon Jan 29, 2018 5:55 pm

Half-duplex UART over a single wire

Postby michcfr » Thu Nov 11, 2021 9:38 pm

Hello,
I need to implement half-duplex UART over a single wire and configure alternatively the same pin for both UART TX and UART RX.
The idea it to remap the pin (attach/detach) using the GPIO matrix.

Can somebody help me to correct switchToTX and switchToRX below that are supposed (but still not working...) to do RX/TX switching of the single wire.

For the tests, I use two ESP32 boards connected together throught the GPIO17.


Thank you,
Michel

Code: Select all

#define SingleWire_pin 17
HardwareSerial MySerial(1);

void setup() {
  //begins with the UART1 standard pins: 17 and 16. The pin 16 is definitively realeased bc no more needed.
  MySerial.begin(115200, SERIAL_8N1, SingleWire_pin, 16);
  pinMatrixOutDetach(16, false, false); 
  ...
}

void switchToTX(){
 pinMatrixOutDetach(SingleWire_pin, false, false);
 pinMode(SingleWire_pin, OUTPUT);
 pinMatrixOutAttach(SingleWire_pin, U1TXD_OUT_IDX, false, false);
}

void switchToRX(){
 pinMatrixOutDetach(SingleWire_pin, false, false);
 pinMode(SingleWire_pin, INPUT);
 pinMatrixInAttach(SingleWire_pin, U1RXD_IN_IDX, false);
}


void loop() {
//before writing over MySerial: switchToTX
switchToTX();
...

//before reading over MySerial: switchToRX
switchToRX();
...

}

Who is online

Users browsing this forum: No registered users and 13 guests