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 write slows down thread

    Scheduled Pinned Locked Moved LoPy
    10 Posts 3 Posters 64 Views 4 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.
    • M Offline
      mbyamukama
      last edited by mbyamukama

      I have the following code on a LoPy4. Firmware version 1.20.2.r4

      def toggleRGB(delay,color,count):
          for j in range(count):
              pycom.rgbled(color)
              time.sleep_ms(delay)
              pycom.rgbled(0x000000)
              time.sleep_ms(delay)
      
      def uart_tx_rx():
          while True:
              # uart.write("some data here\n")
              # time.sleep_ms(30)
              # uart.write("some data here\n")
              # time.sleep_ms(30)
              toggleRGB(5,0xFF69B4,1) #led flash means we are alive
              time.sleep_ms(2500)
      
      _thread.start_new_thread(uart_tx_rx, ())
      

      As shown, the RGB led flashes every 2.5 seconds. But when I comment out the uart.write(), it becomes very slow and indeterminate. Sometimes taking 14 seconds, other times 30 seconds. The uart object has been declared earlier and works well.
      Any idea what's going on?

      robert-hhR J 2 Replies Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @mbyamukama
        last edited by

        @mbyamukama So with UART write if flashes well, and without UART write it does not. What happens if you increase the delay parameter, lets say from 5 to 50?

        J M 2 Replies Last reply Reply Quote 0
        • J Offline
          jcaron @mbyamukama
          last edited by

          @mbyamukama Is the UART used by other things (including any debug info from the OS)? How much data are you writing? What are the UART settings (speed, mostly)?

          14 to 30 seconds seems quite extreme for it to be related to the time needed to actually send the data (at a relatively slow 9600 bps that equates to about 15 to 30 Kbytes of data), but maybe you're actually sending that much or using an even slower speed, or you have something else spewing logs like crazy?

          M 1 Reply Last reply Reply Quote 0
          • J Offline
            jcaron @robert-hh
            last edited by

            @robert-hh I believe it's the opposite. The "comment out" puzzled me as well, I admit, I think OP meant "when I uncomment".

            robert-hhR M 2 Replies Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @jcaron
              last edited by

              @jcaron That's what I was unclear about too, so I asked more specifically. @mbyamukama Which pins do you use for the UART?

              1 Reply Last reply Reply Quote 0
              • M Offline
                mbyamukama @jcaron
                last edited by mbyamukama

                @jcaron Yes. I mean, when I uncomment. I can't correct it unfortunately as the 3600s has already elapsed.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  mbyamukama @robert-hh
                  last edited by mbyamukama

                  @robert-hh It flashes well WITHOUT the uart write and takes a long time otherwise. I am writing very little data. About 150-300 bytes at 115200bps. I am using uart1 on pins P3 and P4. One thing I did not show, because I didn't think it's an issue, is that before the uart write, I pull pin P23 low. This pin controls a fast SPDT analog switch that enables me to multiplex the LoPy4's uart between two different devices. I do not have any reason to believe that is an issue because the unit tests work well.

                  J robert-hhR 2 Replies Last reply Reply Quote 0
                  • J Offline
                    jcaron @mbyamukama
                    last edited by

                    @mbyamukama Since you only mention 2 pins, I suppose you don't use flow control (RTS/CTS)? It shouldn't matter anyway as IIRC write is non-blocking, but you never know...

                    Which UART bus are you using (the number in the constructor)?

                    Can you add logs with timestamps?

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

                      @mbyamukama That's strange. I do not expect P23 to have any side effect. Some crosstalk between P2 and P3 may be more a problem. Since you have already a sleep_ms(30) after each UART write to wait until the data has been sent, can you increase that delay (especially the second one) longer to ensure, that all data has been sent before you flash the LED.

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        mbyamukama @jcaron
                        last edited by

                        @jcaron No it isn't. The only printout i have no control over is the boot printout. Nothing else is using it.

                        1 Reply Last reply Reply Quote 0

                        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