Reliable transfer using UART



  • Hello, Pycom Team,

    Hope you are doing well. So, I am able to transfer 4000 bytes using UART. Need few suggestions. I want reliable transfer from Rasberry Pi and FiPy using UART

    Currently,

    1. I put a newline \n at the end of the message and also attach a header with the message length :ML:50, . 50 is the length of the whole message.
    2. It works fine mostly for small message and if the message are sent are slowly on the UART. However, there are the cases where the UART message can be
    • :ML:50,EEEEE\n
    • :ML:50,DDDD\n:ML:50:EEEE\n or
    • :ML:50,FFFFFFFFFFFF and then in the next read FFFFF\n .

    Not being able to debug the FiPy side makes this more difficult. Knowing that transfer over UART has always been a issue. Is there a library which can be used on both side? Any suggestions are really appreciated.



  • @bitvijays You can use any port for RTS and CTS which is not otherwise used. On FiPy, P5 to P7, P15, P17-P20 are used by the various modems. P4, P8 and P23 are used for the SD card, P12 for the WiFi Antenna switch.

    CTS is an input and so P13, P14 or P16 can be used for it.



  • Hi @robert-hh

    Currently, I have tried using both. The scenario is that UART buffer is defined as 512 bytes and I am trying to transfer large amount of data. (40000 bytes). I came across a old thread of UART RX buffer issue after buffer overflow. Where the data we are transferring is large.

    Where you mentioned that " You were able to do a test with a baud rate of 115200 and 2048 byte and 10k data. With flow control enabled, nothing is lost. Without flow control, data is lost. ".

    So, probably, I should just utilise hardware flow control and things probably should be fine? Also, if it is possible, would it be possible for you to tell a little about your setup? Does P22and P23 port in FiPy refers to RTS and CTS? It seems you used 'P8', 'P9' for RTS and CTS on LoPy4.

    Is there a way to find out which ports can be used for hardware control for FiPy. FiPy Datasheet

    Thank you for your support.



  • @bitvijays >I do not know which uart call you are using. You might use uart.read() or uart.readline().

    uart.read() returns whatever is in the receive buffer at the time of the call. That may be None.

    uart.readline() returns data up to a \n character. If there is not \n character, it returns what's there,

    Both calls are nonblocking by default. You can make them wait for a timeout, using the timeout_chars parameter or uart.init() or the instantiation of the uart object. When used with uart.readline(), the call returns up data up to a \n character and if it's not there, waits until the timeout expires for \n to show up.
    See also: https://docs.pycom.io/firmwareapi/pycom/machine/uart/#app


Log in to reply
 

Pycom on Twitter