• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

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

Question

tarifa    0

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

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 1
Mindovermaster    2,397

Don't swat me down, but I think this is all college questions you are asking. Your last ~10 threads.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.