Page 1 of 1

UARTS1 and 2 appear unusable [SOLVED]

Posted: Wed Sep 13, 2017 7:53 am
by pythoncoder
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?

Re: UARTS1 and 2 appear unusable.

Posted: Wed Sep 13, 2017 8:08 am
by loboris
On ESP32 UART signals can be routed to (almost) any pins using gpio matrix.

Re: UARTS1 and 2 appear unusable.

Posted: Wed Sep 13, 2017 8:16 am
by pythoncoder
Ah, I hadn't appreciated that. Thanks. Is this functionality available in MicroPython?

Re: UARTS1 and 2 appear unusable.

Posted: Wed Sep 13, 2017 9:08 am
by loboris
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.

Re: UARTS1 and 2 appear unusable.

Posted: Wed Sep 13, 2017 4:12 pm
by 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?

Re: UARTS1 and 2 appear unusable.

Posted: Thu Sep 14, 2017 1:41 pm
by loboris
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

Re: UARTS1 and 2 appear unusable.

Posted: Fri Sep 15, 2017 12:39 am
by cheche
[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?

Re: UARTS1 and 2 appear unusable [SOLVED]

Posted: Fri Sep 15, 2017 7:13 am
by pythoncoder
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

Re: UARTS1 and 2 appear unusable [SOLVED]

Posted: Fri Sep 15, 2017 9:17 am
by loboris
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.