• 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

 

 

 

 

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...

Link to comment
Share on other sites

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.