Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Single-wire Serial in T3.5

  1. #1
    Member
    Join Date
    Mar 2021
    Location
    Oceanside, CA
    Posts
    23

    Single-wire Serial in T3.5

    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.

  2. #2
    Quote Originally Posted by choochoo22 View Post
    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/62905...l=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.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,523
    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

  4. #4
    Member
    Join Date
    Mar 2021
    Location
    Oceanside, CA
    Posts
    23
    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);

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,523
    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 by KurtE; 02-13-2022 at 02:17 AM.

  6. #6
    Member
    Join Date
    Mar 2021
    Location
    Oceanside, CA
    Posts
    23
    Thanks, I think I get it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •