• 0

esp32: different use of UART pins: id as paramter directly


Question

hello dear folks, 

 

the UART-use is somewhat interesting: we hafe pin id as paramter directly, eg:

    u=UART(1,9600,tx=4,rx=5)

But in SPI/I2C, it is use pin object, eg:
 

    i2c=I2C(1,sda=Pin(14),scl=Pin(15))

i see some issues here:
- Not all ports support is set eg the tx/rx pins
- some of the existing ports (e.g. esp8266) are related to a so called  machine.Pin while others (e.g. esp32) take a pin number.


from what i see in the docs:

 

cf  the docs https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/uart.html

  Quote

 

The following overview describes functions and data types used to establish communication between ESP32 and some other UART device. The overview reflects a typical workflow when programming ESP32’s UART driver and is broken down into the following sections:

Setting Communication Parameters- baud rate, data bits, stop bits, etc,

Setting Communication Pins- pins the other UART is connected to

Driver Installation- allocate ESP32’s resources for the UART driver

Running UART Communication- send / receive the data

Using Interrupts- trigger interrupts on specific communication events

Deleting Driver- release ESP32’s resources, if UART communication is not required anymore

The minimum to make the UART working is to complete the first four steps, the last two steps are optional.

The driver is identified by uart_port_t, that corresponds to one of the tree UART controllers. Such identification is present in all the following function calls.

Setting Communication Parameters

There are two ways to set the communications parameters for UART. One is to do it in one shot by calling uart_param_config()provided with configuration parameters in uart_config_tstructure.

The alternate way is to configure specific parameters individually by calling dedicated functions:

Baud rate - uart_set_baudrate()

Number of transmitted bits - uart_set_word_length()selected out of uart_word_length_t

Parity control - uart_set_parity()selected out of uart_parity_t

Number of stop bits - uart_set_stop_bits()selected out of uart_stop_bits_t

Hardware flow control mode - uart_set_hw_flow_ctrl()selected out of uart_hw_flowcontrol_t

Communication mode - uart_set_mode()selected out of uart_mode_t

 

 

 

 

Expand  

Configuration example:

 

    const int uart_num = UART_NUM_2;
    uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS,
        .rx_flow_ctrl_thresh = 122,
    };
    // Configure UART parameters
    ESP_ERROR_CHECK(uart_param_config(uart_num, &uart_config));


any idea why this is so.

 

any idea why this is so...

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Both a game adaptation and it's on Amazon I'll set my hopes low
    • You shut your mouth you young fart, that was just a few years ago, lol.
    • Good effort, but unfortunately not very useful in the real world, since it doesn't support UEFI - which is a major drawback. More than that, most PCs these days have Secure Boot enabled by default, so unless you're tech savvy, the average joe is not going to disable Secure Boot - which means automated Windows > Linux migration programs like this will not work. And if you're tech savvy enough to know how to disable Secure Boot, then you're tech savvy enough to just flash a USB drive and install Linux the usual way - after all, the actual installation process is just point-and-click. So I don't see a use case here to be honest, especially considering the lack of UEFI support - especially when you consider that more and more Linux distros are completely dropping BIOS support (eg Fedora dropped it back in 2022). So this program is a bit too late to the party.
    • I agree with open rights group that the age check companies should be regulated but action does need to be taken imo, they may be called irresponsible parents but the fact is that many don't know how to set up blocks. Why should kids suffer because their parents don't know something? I think the UK has always been a bit like this. We don't say healthcare is your responsibility, we tax everyone and make people register with the NHS. We also don't expect everyone to brush their teeth to maintain dental health, we just put fluoride in their water assuming people aren't brushing enough, because some probably aren't or aren't doing it properly. In general, this way of doing things works.
  • Recent Achievements

    • One Month Later
      Falcon.ai earned a badge
      One Month Later
    • Week One Done
      Falcon.ai earned a badge
      Week One Done
    • Dedicated
      EYEREX earned a badge
      Dedicated
    • First Post
      Electronic Person earned a badge
      First Post
    • Week One Done
      CyberCeps666 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      629
    2. 2
      ATLien_0
      237
    3. 3
      Xenon
      165
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!