swap (or change) uart pins on pyboard

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Batman
Posts: 13
Joined: Sun Aug 26, 2018 6:04 pm

swap (or change) uart pins on pyboard

Post by Batman » Mon Nov 02, 2020 9:19 pm

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

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: swap (or change) uart pins on pyboard

Post by jimmo » Tue Nov 03, 2020 1:08 am

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

Post Reply