Page 1 of 1

swap (or change) uart pins on pyboard

Posted: Mon Nov 02, 2020 9:19 pm
by Batman
Hi all

Is it possible to change or specify the pins used by the pyboard for RX and TX for a UART port? For example, x9 is used as tx and x10 as RX, per default for UART(1). But I'd like to swap this around.

It seems that the machine module in micropython might allow for this. But I could not get this to work on the pyboard 1.1. Perhaps, this is not possible on this particular board? In particular, the following code falis with the error "TypeError: extra keyword arguments given".

Code: Select all

uart = machine.UART(1,baudrate=9600)                         
uart.init(baudrate=9600, bits=8, parity=None, stop=1,tx=machine.Pin('X9'), rx=machine.Pin('X10'))
Best

Re: swap (or change) uart pins on pyboard

Posted: Tue Nov 03, 2020 1:08 am
by jimmo
Batman wrote:
Mon Nov 02, 2020 9:19 pm
Perhaps, this is not possible on this particular board? In particular, the following code falis with the error "TypeError: extra keyword arguments given".
In general with machine.X (for X in UART, SPI, I2C, etc), you either specify:
- An ID (which tells it which hardware peripheral to use)
- OR. Individual pins to use (which makes it use the software bit-banging implementation on those pins).

There is no soft UART implementation in MicroPython, which is why you can't specify pins directly.

If you want to swap the pins on the hardware implementation, I know this is possible on the F7xx family (using USARTx CR2 SWAP) but I don't know if this is available on F4xx.

You can however use different pins via the pin alternate function feature. See this recent thread for some notes about using Pin AF for I2C (but same for USART) viewtopic.php?f=3&t=9139