Author Topic: A UART! A UART! My kingdom for a UART!  (Read 6676 times)

0 Members and 1 Guest are viewing this topic.

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1935
  • Country: gb
A UART! A UART! My kingdom for a UART!
« on: January 06, 2023, 10:18:15 pm »
I don't understand WTF Espressif's intentions were with giving the ESP32 three UARTs, but then - for the majority of usage scenarios - making all of them but one unusable. You can't use UART1 because those pins are all taken by flash. You can't realistically dedicate UART0 to other purposes because you need that for programming and debug output. And for UART2, only RX/TX are usable on WROOM modules (not WROVER, because of PSRAM), with RTS/CTS also being nixed by flash. >:( :rant:

So, what's a guy to do if he has an ESP32-based project where essentially all the pins are already in use, but would like to try and squeeze out the use of a UART for something like RS-485?

I have two main questions:

1. Could there be some way of sharing UART0? I am imagining perhaps a mux/switch/buffer that under control of another GPIO switches the RX/TX (and maybe RTS) between the programming/debug header and the RS-485 transceiver.
2. If so, is it possible with the ESP-IDF framework to share UART0 in this manner? By default all log/trace 'console' output is directed there, but can you dynamically switch that off then back again?
 

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: A UART! A UART! My kingdom for a UART!
« Reply #1 on: January 06, 2023, 10:56:20 pm »
At least on the RP2040, which also has a similar external QSPI flash arrangement, one can turn off QSPI flash, executing solely from SRAM, and use those pins designated for it for some other purpose.
 

Online woofy

  • Frequent Contributor
  • **
  • Posts: 512
  • Country: gb
    • Woofys Place
Re: A UART! A UART! My kingdom for a UART!
« Reply #2 on: January 06, 2023, 11:21:27 pm »
I thought the pins could be re-mapped;

// Use GPIO2 and GPIO4 for Serial2
Serial2.begin(115200, SERIAL_8N1, 2, 4);

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 5397
  • Country: nl
Re: A UART! A UART! My kingdom for a UART!
« Reply #3 on: January 06, 2023, 11:47:10 pm »
It's quite common for microcontrollers to have many more functions than they have pins, and as far as I know the ESP32 is pretty constrained in the number of pins.

Teensy 4 may be nice. I think it has 8 uart's.  It also has wired ethernet which is much more reliable than that wireless rubbish. And you can also use the same cable to power from a remote power supply, so no messing with batteries. (100Mbit/s Ethernet uses only 2 wire pairs, the other two pairs are "free").

If you go to chip families such as STM32, you can choose between 10 or so I/O pins to 140 pins or more and there have got to be some UsARTS among that sea of pins.
 

Offline globoy

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: us
Re: A UART! A UART! My kingdom for a UART!
« Reply #4 on: January 06, 2023, 11:48:26 pm »
Serial port pins can be remapped.  As woofy shows for arduino and with uart_set_pin directly under the IDF.

There's also RS-485 support: https://docs.espressif.com/projects/esp-idf/en/v5.0/esp32/api-reference/peripherals/uart.html
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17837
  • Country: fr
Re: A UART! A UART! My kingdom for a UART!
« Reply #5 on: January 07, 2023, 12:19:51 am »
It's just that those MCUs have a ridiculously low number of GPIOs in general. But you get what you pay for.
 

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1935
  • Country: gb
Re: A UART! A UART! My kingdom for a UART!
« Reply #6 on: January 07, 2023, 12:46:43 am »
Serial port pins can be remapped.  As woofy shows for arduino and with uart_set_pin directly under the IDF.

Oh, they can, can they? I always thought that pin muxing on the ESP32 was just for general-purpose IO, and not available for most peripherals.

Serves me right for not looking at the documentation before assuming. :)

Although, it still doesn't help me much given that practically all pins are already in use. :( So I guess my original questions still stand.
 

Offline Geoff-AU

  • Frequent Contributor
  • **
  • Posts: 424
  • Country: au
Re: A UART! A UART! My kingdom for a UART!
« Reply #7 on: January 07, 2023, 05:22:44 am »
ESP32 has a GPIO matrix for low speed IO and also an IO_MUX for high speed stuff, with more limited flexibility.

I agree that Espressif's logic is a bit odd.  The SPI program flash clobbers the pins labelled SD_DataX, so don't make the mistake of just wiring things up the logical way and expecting it to work.  To get an SD card connected you need to use Function 4 of the IO Mux  |O

Although, it still doesn't help me much given that practically all pins are already in use. :( So I guess my original questions still stand.

Generally when you run out of IO you start hanging expanders off the SPI/I2C bus (either a GPIO expander or a UART or both, some UARTs also come with a few general IO)

 

Offline feecat

  • Newbie
  • Posts: 1
  • Country: 00
Re: A UART! A UART! My kingdom for a UART!
« Reply #8 on: January 07, 2023, 06:15:56 am »
You can use any gpio as RTS/CTS, IO have about 10MHz speed, just like this, GPIO14 is RTS.
UART on esp32 will got delay when high baudrate, so i need directly write txfifo for minimum delay.

Code: [Select]
      if (uart_length > 0)
      {
        //we have message need send
        GPIO.out_w1ts = (1 << GPIO_NUM_14);
        uart_ll_write_txfifo(&UART2, uart_buffer, uart_length);
        while (UART2.status.st_utx_out > 0)
        {
          //FIXME: maybe infinity loop here
        }
        if (uart_length == 1) //if just one byte package, we need add a delay
          ets_delay_us(8);
        GPIO.out_w1tc = (1 << GPIO_NUM_14);
      }
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 12771
  • Country: nz
Re: A UART! A UART! My kingdom for a UART!
« Reply #9 on: January 07, 2023, 06:52:41 am »
Serial port pins can be remapped.  As woofy shows for arduino and with uart_set_pin directly under the IDF.
Oh, they can, can they? I always thought that pin muxing on the ESP32 was just for general-purpose IO, and not available for most peripherals.

Why would you want to remap general-purpose IO, there wouldn't be any point.
Remapping IO is typically for peripherals so you can have more available peripherals than you have physicals pins. This makes the MCU useful to a wider range of people with different needs
« Last Edit: January 07, 2023, 06:55:42 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 
The following users thanked this post: karpouzi9

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1935
  • Country: gb
Re: A UART! A UART! My kingdom for a UART!
« Reply #10 on: January 07, 2023, 02:47:48 pm »
Generally when you run out of IO you start hanging expanders off the SPI/I2C bus (either a GPIO expander or a UART or both, some UARTs also come with a few general IO)

Hmm, yes, I suppose external SPI/I2C UARTs might be a thing. Hadn't occurred to me as I assumed discrete UART ICs were archaic, or would only have parallel interfaces. I could do that - already have some other I2C and SPI devices. But having a quick look, they're all pretty expensive, and many are dual/quad which is unnecessary for my needs.

Does anyone know of any SPI/I2C UARTs with integrated RS-485 transceiver? Could be worth the price if two functions reside in a single chip.
 

Offline HwAoRrDkTopic starter

  • Super Contributor
  • ***
  • Posts: 1935
  • Country: gb
Re: A UART! A UART! My kingdom for a UART!
« Reply #11 on: January 08, 2023, 12:30:47 pm »
Does anyone know of any SPI/I2C UARTs with integrated RS-485 transceiver?

Haha, I found one: the Maxim MAX3140, an SPI UART with integrated RS485 transceiver. But the price! $10+ each! :o :scared: No thanks.
 

Offline bidrohini

  • Regular Contributor
  • *
  • Posts: 201
  • Country: bd
Re: A UART! A UART! My kingdom for a UART!
« Reply #12 on: January 08, 2023, 02:07:03 pm »
https://forum.arduino.cc/t/esp32-using-usart1/890225/4
This thread says that it is possible to remap the USART1 pins of ESP32. I never tried that personally.
 

Offline spostma

  • Regular Contributor
  • *
  • Posts: 191
  • Country: nl
Re: A UART! A UART! My kingdom for a UART!
« Reply #13 on: January 09, 2023, 11:02:50 pm »
maybe these will suit your needs:
SC16IS740_750_760 Single UART with I2C or SPI Interface and IrDA and RS85 support
SC16IS752_762        DUAL UART with I2C or SPI Interface and IrDA and RS85 support

libraries:
https://github.com/nopnop2002/esp-idf-sc16is750
https://community.nxp.com/t5/Other-NXP-Products-Knowledge/SC16IS752-Bare-metal-example-project/ta-p/1105691
https://github.com/agronaut/SC16IS752-micropython-library

module for experimenting:
https://www.aliexpress.com/item/1005004682656027.html
https://www.aliexpress.com/item/1005005076107445.html
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->