UARTS1 and 2 appear unusable [SOLVED]

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
pythoncoder
Posts: 1963
Joined: Fri Jul 18, 2014 8:01 am

UARTS1 and 2 appear unusable [SOLVED]

Post by pythoncoder » Wed Sep 13, 2017 7:53 am

I have an Espressif ESP32-devkit C board with ESP-WROOM-32. One of the attractions of the ESP32 was the hope that at least one UART aside from that used for USB would be available for general use. This appears not to be the case.

The ESP32 has three UARTs U0, U1 and U2.
U0 is used by the USB interface.

U2 uses pins GPIO17 (txd) and GPIO16 (rxd). The use of these pins is deprecated in the ESP32 datasheet. Section 2.2 Note states "ESP32-D2WD’s pins GPIO16, GPIO17, SD_CMD, SD_CLK, SD_DATA_0 and SD_DATA_1 are used for connecting the embedded flash, and are not recommended for other uses."

U1 uses GPIO9 (rxd) and GPIO10 (txd). Alas GPIO9 has very odd characteristics. If you instantiate it as an input, it reads high. If you connect it to 0V the board reboots. If you instantiate it as an output the board reboots. If you instantiate U1 - you've guessed it - the board reboots. [EDIT] It only reboots if a loopback is installed. But this bodes ill for actually using it.

There is nothing on the board schematic to explain the behaviour of GPIO9 so I'm wondering if the MicroPython firmware is using this pin in some way. If so, it's an unfortunate choice of pin.

Any comments or experience of using the UARTs?
Last edited by pythoncoder on Wed Sep 13, 2017 4:13 pm, edited 2 times in total.
Peter Hinch

loboris
Posts: 88
Joined: Fri Oct 02, 2015 6:19 pm

Re: UARTS1 and 2 appear unusable.

Post by loboris » Wed Sep 13, 2017 8:08 am

On ESP32 UART signals can be routed to (almost) any pins using gpio matrix.

User avatar
pythoncoder
Posts: 1963
Joined: Fri Jul 18, 2014 8:01 am

Re: UARTS1 and 2 appear unusable.

Post by pythoncoder » Wed Sep 13, 2017 8:16 am

Ah, I hadn't appreciated that. Thanks. Is this functionality available in MicroPython?
Peter Hinch

loboris
Posts: 88
Joined: Fri Oct 02, 2015 6:19 pm

Re: UARTS1 and 2 appear unusable.

Post by loboris » Wed Sep 13, 2017 9:08 am

Just set UART tx&rx pins, for testing connect some terminal emulator to the selected lines:

Code: Select all

>>> uart = machine.UART(1,baudrate=115200,tx=25,rx=26)
>>> uart
UART(1, baudrate=115200, bits=8, parity=None, stop=1, tx=25, rx=26, rts=-1, cts=-1, timeout=0, timeout_char=1)
>>> uart.write("MicroPython\n")
12
>>> uart.read()
b'Hi, MicroPython\r'
>>> 
The limitation is that you can't use ESP32 input-only pins (34~39) as TX.

User avatar
pythoncoder
Posts: 1963
Joined: Fri Jul 18, 2014 8:01 am

Re: UARTS1 and 2 appear unusable.

Post by pythoncoder » Wed Sep 13, 2017 4:12 pm

Awesome - that works :D

A couple of queries to satisfy my curiosity. Does this ability to remap in Python apply to other peripherals such as I2C and SPI? And do you happen to know the reason for the strange behaviour of GPIO9?
Peter Hinch

loboris
Posts: 88
Joined: Fri Oct 02, 2015 6:19 pm

Re: UARTS1 and 2 appear unusable.

Post by loboris » Thu Sep 14, 2017 1:41 pm

pythoncoder wrote:Awesome - that works :D

A couple of queries to satisfy my curiosity. Does this ability to remap in Python apply to other peripherals such as I2C and SPI? And do you happen to know the reason for the strange behaviour of GPIO9?
Yes, I2C and SPI pins (I'm only using hw i2c&spi) can be selected from (almost) any GPIO.
About GPIO9 issues, see this post from ESP32 forum and esp-idf documentation

User avatar
cheche
Posts: 2
Joined: Thu Sep 07, 2017 1:56 am

Re: UARTS1 and 2 appear unusable.

Post by cheche » Fri Sep 15, 2017 12:39 am

[quote="loboris"][quote="pythoncoder"]Awesome - that works :D

A couple of queries to satisfy my curiosity. Does this ability to remap in Python apply to other peripherals such as I2C and SPI? And do you happen to know the reason for the strange behaviour of GPIO9?[/quote]
Yes, I2C and SPI pins (I'm only using hw i2c&spi) can be selected from (almost) any GPIO.
About GPIO9 issues, see [url=https://www.esp32.com/viewtopic.php?t=1457#p6602]this post[/url] from ESP32 forum and [url=http://esp-idf.readthedocs.io/en/latest ... /gpio.html]esp-idf documentation[/url][/quote]
hi!can use hardware SPI on esp32 board with micropython?how?

User avatar
pythoncoder
Posts: 1963
Joined: Fri Jul 18, 2014 8:01 am

Re: UARTS1 and 2 appear unusable [SOLVED]

Post by pythoncoder » Fri Sep 15, 2017 7:13 am

It seems the ESP32 chip and the ESP-WROOM-32 module reserve different pins for Flash:
6, 7, 8, 9, 10, 11 : ESP-WROOM-32 http://espressif.com/sites/default/file ... eet_en.pdf
6,7,8,15,16,17 : ESP32 https://www.espressif.com/sites/default ... eet_en.pdf
Peter Hinch

loboris
Posts: 88
Joined: Fri Oct 02, 2015 6:19 pm

Re: UARTS1 and 2 appear unusable [SOLVED]

Post by loboris » Fri Sep 15, 2017 9:17 am

ESP32-D2WD is the chip with embedded 2MB flash and the internal flash is connected to different pins (GPIO16, GPIO17, SD_CMD, SD_CLK, SD_DATA_0 and SD_DATA_1 ).
If SPIRAM (external SPI RAM, usually 4MB) is included in the design (like on ESP32-WROVER module) , GPIO16 & GPIO17 are additionaly used as SPIRAM CS&CLK and are not available to the user.

Post Reply