Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    uart 1 and 2 L04 module

    Scheduled Pinned Locked Moved LoPy
    5 Posts 3 Posters 57 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      Alessandro Cortese
      last edited by

      Good morning everybody,

      i am developing a python script for L04 module where i need to enable UART1 and UART2 at the same time.

      line 1: uart1 = UART(1, 115200) # init with given baudrate
      line2: uart1.init(115200, bits=8, parity=None, stop=1, pins=('P3', 'P4')) # init with given parameters

      line3: uart2 = UART(2, 115200) # init with given baudrate
      line4: uart2.init(115200, bits=8, parity=None, stop=1, pins=('P19', 'P20')) # init with given parameters

      I need to read data from UART1 and redirect it to UART2.
      Everything works if i do no enable uart2 (line 3 and 4) but unfortunately, when i enable the second uart, i do not receive anything from uart1 (i print the result in REPL).

      Do you have suggestions?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • E Offline
        Elizar
        last edited by

        What exactly do you mean by "enable the second uart"?

        Reading from a serial port is usually a blocking operation unless you specified some timeout time before the read. Did you?

        Another possible way is to check if there is something to read like

        while true:
           if uart1.any():   msg1 = uart1.readline()
           if uart2.any():   msg2 = uart2.readline()
           ...
        

        That way, the readline() operations will never block the loop.

        1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @Alessandro Cortese
          last edited by

          @Alessandro-Cortese Do not use the init calls. put the arguments from the init call into the constructor. Line 3 will set up uart2 at the default pins, which are changed in line 4.

          A 1 Reply Last reply Reply Quote 1
          • A Offline
            Alessandro Cortese @robert-hh
            last edited by

            @robert-hh it works!! Many thanks for your help :) what could be the reason of that behaviour about init calls?

            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @Alessandro Cortese
              last edited by

              @Alessandro-Cortese That's how it is implemented. It is not the init call, it is the constructor. if you call:
              uart2 = UART(2, 115200) # init with given baudrate
              the default pins for UART 2 are used. These are P3 and P4, which are then deassigned from UART 1. Putting all settings into the constructor call avoids that pitfall, and it is shorter code.

              1 Reply Last reply Reply Quote 1

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom