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

Thread: Bi Directional Serial Comm

  1. #1
    Junior Member
    Join Date
    Jun 2018
    Posts
    10

    Bi Directional Serial Comm

    hi,

    I have an ESP32 hooked up to the Teensy 4.1 at Serial 3.

    The teensy sends a json to the ESP that then Broadcasts it to my MQtt Server. This works without a problem, i have delay every 2 seconds.

    However, Should The Esp32 receive a message, it needs to pass it on the the Teensy, for action.

    I am having problems with this transmission, back to the Teensy. It doesn't seem to want to read it, I have a Flowcontrol pin, that i use that if the Teensy is Transmitting it pulls it high, then the ESP Knows it must receive, and if it is low then the ESP is clear to transmit. This works for Teensy --> ESP transmission, but not ESP --> Teensy transmission.

    I have code that reads a start char '<' and End Char '>', this works great on the Teensy to ESP, but just cant switch it.

    Any Ideas on how to run Bidirectional Serial

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    472
    Are you trying to do half-duplex on a single wire, as opposed to full duplex using two signals, each uni-directional?

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,912
    As @MarkT asked, it is really hard to know what you are doing, without knowing more of the details.

    Example: if you hooked up T4.1 to ESP32, with TX3(14) connected to the RX of the ESP TTL Serial and RX3(15) to the TTL Serial TX pin on ESP32, You should be able to simply do something like SerialX.write()... on the ESP32, and the Teensy4.1 should be able to simple do: if (Serial3.available()) ... and call Serial3.read() to read in the stuff from the ESP32...

    Now if you are trying to do this, by using one IO pin in Half duplex mode. The Teensy can support half duplex on the TX pins of the Serial ports.

    There is some better support for it currently waiting in a Pull Request: https://github.com/PaulStoffregen/cores/pull/489

    Can go into more details on how to setup half duplex, by updating some of the hardware registers and the like. How to do it, is in that Pull Request, plus can go into more details.
    Without PR, you still probably want to:

    On T4.x
    a) Enable PU resistor and the like on the TX pin
    b) at Serial3.begin() time you need to update the CTRL register with stuff to enable half duplex:
    if (half_duplex_mode_) ctrl |= (LPUART_CTRL_LOOPS | LPUART_CTRL_RSRC);

    c) To then write to this pin you need to set the port->CTRL |= LPUART_CTRL_TXDIR;
    bit in the CTRL register. And clear that bit to read...

    I have code at different places, that do this, like (...github.com/kurte/BioloidSerial) has code. What I typically do is when I want to write something over the half duplex... Note: in this case the code is always running in master mode and typically only get things back if I sent something out (Servo request) and the servo that the request to has a response...

    But what I do is:
    <Set the TXDIR> // Puts me in write mode...
    (In my case I may do Serial3.clear() to remove any previous data I may have received)
    Write out my messages
    Serial3.flush(); // wait until the device completely outputs the last bits of the data
    <clear the TXDIR> puts me back in Read mode

    In your case with IO pin to connect. Before going into write mode, should probably first detect state of your IO pin and decide if it can go into write mode or not. And when maybe to do reads...

Posting Permissions

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