0

I am currently using a Raspberry Pi Pico with MicroPython 1.16 and using its UART to simulate a sensor using a serial protocol with a transmitter. The transmitter only using the data wire and ground meaning RX and TX are physically tied so my UART RX and TX will also be tied. This causes my receive line to pickup whatever the transmit line sends to the transmitter as well. I want to try to clear this by simply turning off and back on the UART port.

I have already implemented this same project and idea using PySerial and an FTDI driver and would use the serial.open() and close() to clear the buffer instead of the actual method reset_input_buffer() that would not work properly. This is the reasoning behind wanting to deinitialize and reinitialize the UART port.

I was wondering if the MicroPython UART.init() and deinit() methods do not work as the documentation specifies since the interpreter gives me a AttributeError: 'UART' object has no attribute 'init' micropython same happens for 'deinit' as well. Or if anyone knows how to clear the input buffer for a UART port?

  • I don't see them in the source files, so maybe they just didn't get added yet? Maybe see if CircuitPython docs have that feature? To clear the buffer... use machine.mem32 and read the registers directly? Icky, I know. – aMike Aug 28 '21 at 23:09
  • Hi there @aMike, thank you for the speedy response! I have tried looking for documentation on how to do this in the MicroPython docs and could not find much myself (likely me). But once I do find it, does it mean this method you propose will involve reading registers and converting them from hex values instead bytes? – Claudio Rodriguez Aug 30 '21 at 15:37
  • Yes, we'd read the UARTDR data register until the Rcv FIFO empy bit goes high in the UARTFR register, to drain the receive FIFO buffer. We don't care what they are, do we? Just numbers to throw away. However, now that I think about it more, maybe this will really confuse MP and whatever code they have to control the RP2040 UART... Maybe best is to see what other ports have for UART init/deinit and copy it over to the RP2040 port? Wish I had a better answer. – aMike Aug 31 '21 at 16:51
  • Micropython 1.17 came out in the last few days, and there were some UART changes in the Pico port. Maybe see if that helped anything for you? – aMike Sep 02 '21 at 18:13
  • @aMike thank you so much, I actually moved away from this project only to come back to this news now and am installing new firmware to the Pico! Thank you so much! – Claudio Rodriguez Sep 18 '21 at 20:24

0 Answers0