mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
uart: update register headers and examples for S3
This commit is contained in:
parent
a6068ef259
commit
a29a6ceef0
@ -509,7 +509,7 @@ esp_err_t uart_enable_pattern_det_baud_intr(uart_port_t uart_num, char pattern_c
|
||||
at_cmd.gap_tout = chr_tout * uart_div;
|
||||
at_cmd.pre_idle = pre_idle * uart_div;
|
||||
at_cmd.post_idle = post_idle * uart_div;
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#else
|
||||
at_cmd.gap_tout = chr_tout;
|
||||
at_cmd.pre_idle = pre_idle;
|
||||
at_cmd.post_idle = post_idle;
|
||||
|
@ -144,8 +144,8 @@ FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud)
|
||||
uint32_t clk_div = ((sclk_freq) << 4) / (baud * sclk_div);
|
||||
// The baud rate configuration register is divided into
|
||||
// an integer part and a fractional part.
|
||||
hw->clk_div.div_int = clk_div >> 4;
|
||||
hw->clk_div.div_frag = clk_div & 0xf;
|
||||
hw->clkdiv.clkdiv = clk_div >> 4;
|
||||
hw->clkdiv.clkdiv_frag = clk_div & 0xf;
|
||||
hw->clk_conf.sclk_div_num = sclk_div - 1;
|
||||
#undef DIV_UP
|
||||
}
|
||||
@ -160,8 +160,8 @@ FORCE_INLINE_ATTR void uart_ll_set_baudrate(uart_dev_t *hw, uint32_t baud)
|
||||
FORCE_INLINE_ATTR uint32_t uart_ll_get_baudrate(uart_dev_t *hw)
|
||||
{
|
||||
uint32_t sclk_freq = uart_ll_get_sclk_freq(hw);
|
||||
typeof(hw->clk_div) div_reg = hw->clk_div;
|
||||
return ((sclk_freq << 4)) / (((div_reg.div_int << 4) | div_reg.div_frag) * (hw->clk_conf.sclk_div_num + 1));
|
||||
uart_clkdiv_reg_t div_reg = hw->clkdiv;
|
||||
return ((sclk_freq << 4)) / (((div_reg.clkdiv << 4) | div_reg.clkdiv_frag) * (hw->clk_conf.sclk_div_num + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -239,7 +239,7 @@ FORCE_INLINE_ATTR uint32_t uart_ll_get_intr_ena_status(uart_dev_t *hw)
|
||||
FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_t rd_len)
|
||||
{
|
||||
for (int i = 0; i < (int)rd_len; i++) {
|
||||
buf[i] = hw->ahb_fifo.rw_byte;
|
||||
buf[i] = hw->fifo.rxfifo_rd_byte;
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ FORCE_INLINE_ATTR void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_
|
||||
FORCE_INLINE_ATTR void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len)
|
||||
{
|
||||
for (int i = 0; i < (int)wr_len; i++) {
|
||||
hw->ahb_fifo.rw_byte = buf[i];
|
||||
hw->fifo.rxfifo_rd_byte = buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -523,7 +523,7 @@ FORCE_INLINE_ATTR void uart_ll_set_sw_flow_ctrl(uart_dev_t *hw, uart_sw_flowctrl
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_set_at_cmd_char(uart_dev_t *hw, uart_at_cmd_t *cmd_char)
|
||||
{
|
||||
hw->at_cmd_char.data = cmd_char->cmd_char;
|
||||
hw->at_cmd_char.at_cmd_char = cmd_char->cmd_char;
|
||||
hw->at_cmd_char.char_num = cmd_char->char_num;
|
||||
hw->at_cmd_postcnt.post_idle_num = cmd_char->post_idle;
|
||||
hw->at_cmd_precnt.pre_idle_num = cmd_char->pre_idle;
|
||||
@ -593,9 +593,9 @@ FORCE_INLINE_ATTR void uart_ll_set_wakeup_thrd(uart_dev_t *hw, uint32_t wakeup_t
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_set_mode_normal(uart_dev_t *hw)
|
||||
{
|
||||
hw->rs485_conf.en = 0;
|
||||
hw->rs485_conf.tx_rx_en = 0;
|
||||
hw->rs485_conf.rx_busy_tx_en = 0;
|
||||
hw->rs485_conf.rs485_en = 0;
|
||||
hw->rs485_conf.rs485tx_rx_en= 0;
|
||||
hw->rs485_conf.rs485rxby_tx_en = 0;
|
||||
hw->conf0.irda_en = 0;
|
||||
}
|
||||
|
||||
@ -609,11 +609,11 @@ FORCE_INLINE_ATTR void uart_ll_set_mode_normal(uart_dev_t *hw)
|
||||
FORCE_INLINE_ATTR void uart_ll_set_mode_rs485_app_ctrl(uart_dev_t *hw)
|
||||
{
|
||||
// Application software control, remove echo
|
||||
hw->rs485_conf.rx_busy_tx_en = 1;
|
||||
hw->rs485_conf.rs485rxby_tx_en = 1;
|
||||
hw->conf0.irda_en = 0;
|
||||
hw->conf0.sw_rts = 0;
|
||||
hw->conf0.irda_en = 0;
|
||||
hw->rs485_conf.en = 1;
|
||||
hw->rs485_conf.rs485_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -628,11 +628,11 @@ FORCE_INLINE_ATTR void uart_ll_set_mode_rs485_half_duplex(uart_dev_t *hw)
|
||||
// Enable receiver, sw_rts = 1 generates low level on RTS pin
|
||||
hw->conf0.sw_rts = 1;
|
||||
// Must be set to 0 to automatically remove echo
|
||||
hw->rs485_conf.tx_rx_en = 0;
|
||||
hw->rs485_conf.rs485tx_rx_en = 0;
|
||||
// This is to void collision
|
||||
hw->rs485_conf.rx_busy_tx_en = 1;
|
||||
hw->rs485_conf.rs485rxby_tx_en = 1;
|
||||
hw->conf0.irda_en = 0;
|
||||
hw->rs485_conf.en = 1;
|
||||
hw->rs485_conf.rs485_en= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -646,11 +646,11 @@ FORCE_INLINE_ATTR void uart_ll_set_mode_collision_detect(uart_dev_t *hw)
|
||||
{
|
||||
hw->conf0.irda_en = 0;
|
||||
// Transmitters output signal loop back to the receivers input signal
|
||||
hw->rs485_conf.tx_rx_en = 1 ;
|
||||
hw->rs485_conf.rs485tx_rx_en = 1 ;
|
||||
// Transmitter should send data when the receiver is busy
|
||||
hw->rs485_conf.rx_busy_tx_en = 1;
|
||||
hw->rs485_conf.rs485rxby_tx_en = 1;
|
||||
hw->conf0.sw_rts = 0;
|
||||
hw->rs485_conf.en = 1;
|
||||
hw->rs485_conf.rs485_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -662,9 +662,9 @@ FORCE_INLINE_ATTR void uart_ll_set_mode_collision_detect(uart_dev_t *hw)
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_set_mode_irda(uart_dev_t *hw)
|
||||
{
|
||||
hw->rs485_conf.en = 0;
|
||||
hw->rs485_conf.tx_rx_en = 0;
|
||||
hw->rs485_conf.rx_busy_tx_en = 0;
|
||||
hw->rs485_conf.rs485_en = 0;
|
||||
hw->rs485_conf.rs485tx_rx_en = 0;
|
||||
hw->rs485_conf.rs485rxby_tx_en = 0;
|
||||
hw->conf0.sw_rts = 0;
|
||||
hw->conf0.irda_en = 1;
|
||||
}
|
||||
@ -710,7 +710,7 @@ FORCE_INLINE_ATTR void uart_ll_set_mode(uart_dev_t *hw, uart_mode_t mode)
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_get_at_cmd_char(uart_dev_t *hw, uint8_t *cmd_char, uint8_t *char_num)
|
||||
{
|
||||
*cmd_char = hw->at_cmd_char.data;
|
||||
*cmd_char = hw->at_cmd_char.at_cmd_char;
|
||||
*char_num = hw->at_cmd_char.char_num;
|
||||
}
|
||||
|
||||
@ -799,7 +799,7 @@ FORCE_INLINE_ATTR void uart_ll_set_loop_back(uart_dev_t *hw, bool loop_back_en)
|
||||
*/
|
||||
FORCE_INLINE_ATTR void uart_ll_inverse_signal(uart_dev_t *hw, uint32_t inv_mask)
|
||||
{
|
||||
typeof(hw->conf0) conf0_reg = hw->conf0;
|
||||
uart_conf0_reg_t conf0_reg = hw->conf0;
|
||||
conf0_reg.irda_tx_inv = (inv_mask & UART_SIGNAL_IRDA_TX_INV) ? 1 : 0;
|
||||
conf0_reg.irda_rx_inv = (inv_mask & UART_SIGNAL_IRDA_RX_INV) ? 1 : 0;
|
||||
conf0_reg.rxd_inv = (inv_mask & UART_SIGNAL_RXD_INV) ? 1 : 0;
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,7 @@
|
||||
#include "driver/uart_select.h"
|
||||
#include "esp_rom_uart.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/uart_ll.h"
|
||||
|
||||
// TODO: make the number of UARTs chip dependent
|
||||
#define UART_NUM SOC_UART_NUM
|
||||
@ -158,14 +159,13 @@ static int uart_open(const char * path, int flags, int mode)
|
||||
static void uart_tx_char(int fd, int c)
|
||||
{
|
||||
uart_dev_t* uart = s_ctx[fd]->uart;
|
||||
while (uart->status.txfifo_cnt >= 127) {
|
||||
const uint8_t ch = (uint8_t) c;
|
||||
|
||||
while (uart_ll_get_txfifo_len(uart) < 2) {
|
||||
;
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
uart->fifo.rw_byte = c;
|
||||
#else // CONFIG_IDF_TARGET_ESP32
|
||||
uart->ahb_fifo.rw_byte = c;
|
||||
#endif
|
||||
|
||||
uart_ll_write_txfifo(uart, &ch, 1);
|
||||
}
|
||||
|
||||
static void uart_tx_char_via_driver(int fd, int c)
|
||||
@ -177,14 +177,13 @@ static void uart_tx_char_via_driver(int fd, int c)
|
||||
static int uart_rx_char(int fd)
|
||||
{
|
||||
uart_dev_t* uart = s_ctx[fd]->uart;
|
||||
if (uart->status.rxfifo_cnt == 0) {
|
||||
uint8_t ch;
|
||||
if (uart_ll_get_rxfifo_len(uart) == 0) {
|
||||
return NONE;
|
||||
}
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
return uart->fifo.rw_byte;
|
||||
#else // CONFIG_IDF_TARGET_ESP32
|
||||
return READ_PERI_REG(UART_FIFO_AHB_REG(fd));
|
||||
#endif
|
||||
uart_ll_read_rxfifo(uart, &ch, 1);
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
static int uart_rx_char_via_driver(int fd)
|
||||
|
@ -1,20 +1,20 @@
|
||||
UART
|
||||
====
|
||||
|
||||
{IDF_TARGET_UART_NUM:default = "UART_NUM_1", esp32 = "UART_NUM_2", esp32s2 = "UART_NUM_1"}
|
||||
{IDF_TARGET_UART_NUM:default = "UART_NUM_1", esp32 = "UART_NUM_2", esp32s3 = "UART_NUM_2"}
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
A Universal Asynchronous Receiver/Transmitter (UART) is a hardware feature that handles communication (i.e., timing requirements and data framing) using widely-adopted asynchronous serial communication interfaces, such as RS232, RS422, RS485. A UART provides a widely adopted and cheap method to realize full-duplex or half-duplex data exchange among different devices.
|
||||
|
||||
.. only:: esp32
|
||||
.. only:: esp32 or esp32s3
|
||||
|
||||
The ESP32 chip has three UART controllers (UART0, UART1, and UART2) that feature an identical set of registers for ease of programming and flexibility.
|
||||
The {IDF_TARGET_NAME} chip has three UART controllers (UART0, UART1, and UART2), each featuring an identical set of registers to simplify programming and for more flexibility.
|
||||
|
||||
.. only:: esp32s2 or esp32c3
|
||||
|
||||
The {IDF_TARGET_NAME} chip has two UART controllers (UART0 and UART1) that feature an identical set of registers for ease of programming and flexibility.
|
||||
The {IDF_TARGET_NAME} chip has two UART controllers (UART0 and UART1), each featuring an identical set of registers to simplify programming and for more flexibility.
|
||||
|
||||
Each UART controller is independently configurable with parameters such as baud rate, data bit length, bit ordering, number of stop bits, parity bit etc. All the controllers are compatible with UART-enabled devices from various manufacturers and can also support Infrared Data Association protocols (IrDA).
|
||||
|
||||
@ -99,28 +99,10 @@ After setting communication parameters, configure the physical GPIO pins to whic
|
||||
|
||||
The same macro should be specified for pins that will not be used.
|
||||
|
||||
|
||||
|
||||
.. only:: esp32
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
// Set UART pins(TX: IO17 (UART2 default), RX: IO16 (UART2 default), RTS: IO18, CTS: IO19)
|
||||
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, 18, 19));
|
||||
|
||||
.. only:: esp32s2
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
// Set UART pins(TX: IO17 (UART1 default), RX: IO18 (UART1 default), RTS: IO19, CTS: IO20)
|
||||
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, 19, 20));
|
||||
|
||||
.. only:: esp32c3
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
// Set UART pins(TX: IO4, RX: IO5, RTS: IO19, CTS: IO20)
|
||||
ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, 4, 5, 19, 20));
|
||||
// Set UART pins(TX: IO4, RX: IO5, RTS: IO18, CTS: IO19)
|
||||
ESP_ERROR_CHECK(uart_set_pin({IDF_TARGET_UART_NUM}, 4, 5, 18, 19));
|
||||
|
||||
.. _uart-api-driver-installation:
|
||||
|
||||
|
@ -21,20 +21,19 @@ Usually, modules will also output some vendor specific statements which common n
|
||||
|
||||
### Hardware Required
|
||||
|
||||
To run this example, you need an ESP32 dev board (e.g. ESP32-WROVER Kit) or ESP32 core board (e.g. ESP32-DevKitC). For test purpose, you also need a GPS module. Here we take the [ATGM332D-5N](http://www.icofchina.com/pro/mokuai/2016-08-01/5.html) as an example to show how to parse the NMEA statements and output common information such as UTC time, latitude, longitude, altitude, speed and so on.
|
||||
To run this example, you need an ESP32, ESP32-S or ESP32-C series dev board (e.g. ESP32-WROVER Kit). For test purpose, you also need a GPS module. Here we take the [ATGM332D-5N](http://www.icofchina.com/pro/mokuai/2016-08-01/5.html) as an example to show how to parse the NMEA statements and output common information such as UTC time, latitude, longitude, altitude, speed and so on.
|
||||
|
||||
#### Pin Assignment:
|
||||
|
||||
**Note:** The following pin assignments are used by default which can be changed in `nmea_parser_config_t` structure.
|
||||
|
||||
| ESP32 | GPS |
|
||||
| ---------------- | --------------- |
|
||||
| UART-TX (option) | GPS-RX (option) |
|
||||
| UART-RX | GPS-TX |
|
||||
| ESP | GPS |
|
||||
| -------------------------- | --------------- |
|
||||
| UART-RX (GPIO5 by default) | GPS-TX |
|
||||
| GND | GND |
|
||||
| 5V | VCC |
|
||||
|
||||
**Note:** UART TX pin in ESP32 is not necessary if you only use uart to receive data.
|
||||
**Note:** UART TX pin is not necessary if you only use UART to receive data.
|
||||
|
||||
|
||||
### Configure the project
|
||||
@ -91,7 +90,7 @@ I (5067) gps_demo: 2018/12/4 13:59:38 =>
|
||||
speed = 0.685240m/s
|
||||
W (5177) gps_demo: Unknown statement:$GPTXT,01,01,01,ANTENNA OK*35
|
||||
```
|
||||
As shown above, ESP32 finally got the information after parsed the NMEA0183 format statements. But as we didn't add `GPTXT` type statement in the library (that means it is UNKNOWN to NMEA Parser library), so it was propagated to user without any process.
|
||||
As shown above, the ESP board finally got the information after parsed the NMEA0183 format statements. But as we didn't add `GPTXT` type statement in the library (that means it is UNKNOWN to NMEA Parser library), so it was propagated to user without any process.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
@ -1,5 +1,16 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config NMEA_PARSER_UART_RXD
|
||||
int "UART RXD pin number"
|
||||
range 0 34 if IDF_TARGET_ESP32
|
||||
range 0 46 if IDF_TARGET_ESP32S2
|
||||
range 0 48 if IDF_TARGET_ESP32S3
|
||||
range 0 19 if IDF_TARGET_ESP32C3
|
||||
default 5
|
||||
help
|
||||
GPIO number for UART RX pin. See UART documentation for more information
|
||||
about available pin numbers for UART.
|
||||
|
||||
config NMEA_PARSER_RING_BUFFER_SIZE
|
||||
int "NMEA Parser Ring Buffer Size"
|
||||
range 0 2048
|
||||
|
@ -13,7 +13,7 @@ The example starts two FreeRTOS tasks:
|
||||
|
||||
### Hardware Required
|
||||
|
||||
The example can be run on any commonly available ESP32 development board. You will need a USB cable to connect the
|
||||
The example can be run on any commonly available ESP32, ESP32-S and ESP32-C series based development board. You will need a USB cable to connect the
|
||||
development board to a computer, and a simple one-wire cable for shorting two pins of the board.
|
||||
|
||||
### Setup the Hardware
|
||||
|
@ -9,23 +9,23 @@ configured UART.
|
||||
|
||||
### Hardware Required
|
||||
|
||||
The example can be run on any ESP32 or ESP32-S2 based development board connected to a PC with a single USB cable for flashing and
|
||||
The example can be run on any ESP32, ESP32-S and ESP32-C series based development board connected to a computer with a single USB cable for flashing and
|
||||
monitoring. The external interface should have 3.3V outputs. You may use e.g. 3.3V compatible USB-to-Serial dongle.
|
||||
|
||||
### Setup the Hardware
|
||||
|
||||
Connect the external serial interface to the ESP32(S2) board as follows.
|
||||
Connect the external serial interface to the board as follows.
|
||||
|
||||
```
|
||||
---------------------------------------------------------------------------------------
|
||||
| Target chip Interface | #define | Default ESP32(S2) Pin| External UART Pin |
|
||||
| Target chip Interface | #define | Default ESP Pin | External UART Pin |
|
||||
| ----------------------|------------------|----------------------|--------------------
|
||||
| Transmit Data (TxD) | EXAMPLE_UART_TXD | GPIO4 | RxD |
|
||||
| Receive Data (RxD) | EXAMPLE_UART_RXD | GPIO5 | TxD |
|
||||
| Ground | n/a | GND | GND |
|
||||
---------------------------------------------------------------------------------------
|
||||
```
|
||||
Note: The GPIO22 - GPIO25 can not be used with ESP32-S2 chip because they are reserved for internal use. Please refer to UART documentation for selected target.
|
||||
Note: Some GPIOs can not be used with certain chips because they are reserved for internal use. Please refer to UART documentation for selected target.
|
||||
|
||||
Optionally, you can set-up and use a serial interface that has RTS and CTS signals in order to verify that the
|
||||
hardware control flow works. Connect the extra signals according to the following table, configure both extra pins in
|
||||
@ -35,7 +35,7 @@ UART1 driver to use the hardware flow control by setting `.flow_ctrl = UART_HW_F
|
||||
|
||||
```
|
||||
--------------------------------------------------------------------------------------
|
||||
| Target chip Interface | #define | Default ESP32(S2) Pin| External UART Pin |
|
||||
| Target chip Interface | #define | Default ESP Pin | External UART Pin |
|
||||
| ----------------------|-----------------|----------------------|--------------------
|
||||
| Transmit Data (TxD) | ECHO_TEST_RTS | GPIO18 | CTS |
|
||||
| Receive Data (RxD) | ECHO_TEST_CTS | GPIO19 | RTS |
|
||||
@ -65,8 +65,7 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
|
||||
|
||||
## Example Output
|
||||
|
||||
Type some characters in the terminal connected to the external serial interface. As result you should see echo in the
|
||||
terminal which is used for flashing and monitoring. You can verify if the echo indeed comes from ESP32(S2) board by
|
||||
Type some characters in the terminal connected to the external serial interface. As result you should see echo in the same terminal which you used for typing the characters. You can verify if the echo indeed comes from ESP board by
|
||||
disconnecting either `TxD` or `RxD` pin: no characters will appear when typing.
|
||||
|
||||
## Troubleshooting
|
||||
|
@ -2,9 +2,9 @@ menu "Echo Example Configuration"
|
||||
|
||||
config EXAMPLE_UART_PORT_NUM
|
||||
int "UART port number"
|
||||
range 0 2 if IDF_TARGET_ESP32
|
||||
range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
|
||||
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
|
||||
default 2 if IDF_TARGET_ESP32
|
||||
default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
|
||||
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
|
||||
help
|
||||
UART communication port number for the example.
|
||||
@ -20,7 +20,7 @@ menu "Echo Example Configuration"
|
||||
config EXAMPLE_UART_RXD
|
||||
int "UART RXD pin number"
|
||||
range 0 34 if IDF_TARGET_ESP32
|
||||
range 0 46 if IDF_TARGET_ESP32S2
|
||||
range 0 46 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
range 0 19 if IDF_TARGET_ESP32C3
|
||||
default 5
|
||||
help
|
||||
@ -30,7 +30,7 @@ menu "Echo Example Configuration"
|
||||
config EXAMPLE_UART_TXD
|
||||
int "UART TXD pin number"
|
||||
range 0 34 if IDF_TARGET_ESP32
|
||||
range 0 46 if IDF_TARGET_ESP32S2
|
||||
range 0 46 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
range 0 19 if IDF_TARGET_ESP32C3
|
||||
default 4
|
||||
help
|
||||
|
@ -9,7 +9,7 @@ The approach demonstrated in this example can be used in user application to tra
|
||||
## How to use example
|
||||
|
||||
### Hardware Required
|
||||
PC + USB Serial adapter connected to USB port + RS485 line drivers + ESP32-WROVER-KIT board.
|
||||
PC + USB Serial adapter connected to USB port + RS485 line drivers + ESP32, ESP32-S or ESP32-C series based board.
|
||||
The MAX485 line driver is used for example below but other similar chips can be used as well.
|
||||
|
||||
#### RS485 example connection circuit schematic:
|
||||
@ -20,7 +20,7 @@ The MAX485 line driver is used for example below but other similar chips can be
|
||||
RXD <------| RO | | RO|-----> RXD
|
||||
| B|---------------|B |
|
||||
TXD ------>| DI MAX485 | \ / | MAX485 DI|<----- TXD
|
||||
ESP32-WROVER-KIT | | RS-485 side | | SERIAL ADAPTER SIDE
|
||||
ESP dev kit | | RS-485 side | | SERIAL ADAPTER SIDE
|
||||
RTS --+--->| DE | / \ | DE|---+
|
||||
| | A|---------------|A | |
|
||||
+----| /RE | | /RE|---+-- RTS
|
||||
@ -29,19 +29,19 @@ ESP32-WROVER-KIT | | RS-485 side | | SERIAL AD
|
||||
--- ---
|
||||
```
|
||||
|
||||
#### Connect an external RS485 serial interface to an ESP32 board
|
||||
Connect USB to RS485 adapter to computer and connect its D+, D- output lines with the D+, D- lines of RS485 line driver connected to ESP32 (See picture above).
|
||||
#### Connect an external RS485 serial interface to an ESP board
|
||||
Connect USB to RS485 adapter to computer and connect its D+, D- output lines with the D+, D- lines of RS485 line driver connected to the ESP board (See picture above). To view or adjust default pins please see the `Echo RS485 Example Configuration` submenu in `idf.py menuconfig`.
|
||||
```
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
| ESP32 Interface | #define | Default ESP32 Pin | Default ESP32-S2 Pins | External RS485 Driver Pin |
|
||||
| ----------------------|--------------------|-----------------------|-----------------------|---------------------------|
|
||||
| Transmit Data (TxD) | CONFIG_MB_UART_TXD | GPIO23 | GPIO20 | DI |
|
||||
| Receive Data (RxD) | CONFIG_MB_UART_RXD | GPIO22 | GPIO19 | RO |
|
||||
| Request To Send (RTS) | CONFIG_MB_UART_RTS | GPIO18 | GPIO18 | ~RE/DE |
|
||||
| Ground | n/a | GND | GND | GND |
|
||||
--------------------------------------------------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------------------------
|
||||
| ESP Interface | #define | Default ESP Pin | External RS485 Driver Pin |
|
||||
| ----------------------|--------------------|-----------------------|---------------------------|
|
||||
| Transmit Data (TxD) | CONFIG_MB_UART_TXD | CONFIG_ECHO_UART_TXD | DI |
|
||||
| Receive Data (RxD) | CONFIG_MB_UART_RXD | CONFIG_ECHO_UART_RXD | RO |
|
||||
| Request To Send (RTS) | CONFIG_MB_UART_RTS | CONFIG_ECHO_UART_RTS | ~RE/DE |
|
||||
| Ground | n/a | GND | GND |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
```
|
||||
Note: The GPIO22 - GPIO25 can not be used with ESP32-S2 chip because they are used for flash chip connection. Please refer to UART documentation for selected target.
|
||||
Note: Some GPIOs can not be used with some chip because they are used for flash chip connection. Please refer to UART documentation for selected target.
|
||||
|
||||
### Configure the project
|
||||
```
|
||||
@ -62,7 +62,7 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui
|
||||
Refer to the example and set up a serial terminal program to the same settings as of UART in ESP32-WROVER-KIT board.
|
||||
Open the external serial interface in the terminal. By default if no any symbols are received, the application sends character `.` to check transmission side.
|
||||
When typing message and push send button in the terminal you should see the message `RS485 Received: [ your message ]`, where "your message" is the message you sent from terminal.
|
||||
Verify if echo indeed comes from ESP32 by disconnecting either `TxD` or `RxD` pin. Once done there should be no any `.` displayed.
|
||||
Verify if echo indeed comes from your board by disconnecting either `TxD` or `RxD` pin. Once done there should be no any `.` displayed.
|
||||
|
||||
## Example Output
|
||||
Example output of the application:
|
||||
|
@ -2,9 +2,9 @@ menu "Echo RS485 Example Configuration"
|
||||
|
||||
config ECHO_UART_PORT_NUM
|
||||
int "UART port number"
|
||||
range 0 2 if IDF_TARGET_ESP32
|
||||
range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
|
||||
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
|
||||
default 2 if IDF_TARGET_ESP32
|
||||
default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
|
||||
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
|
||||
help
|
||||
UART communication port number for the example.
|
||||
@ -23,8 +23,9 @@ menu "Echo RS485 Example Configuration"
|
||||
default 22 if IDF_TARGET_ESP32
|
||||
range 0 46 if IDF_TARGET_ESP32S2
|
||||
default 19 if IDF_TARGET_ESP32S2
|
||||
range 0 48 if IDF_TARGET_ESP32S3
|
||||
range 0 19 if IDF_TARGET_ESP32C3
|
||||
default 5 if IDF_TARGET_ESP32C3
|
||||
default 5 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
help
|
||||
GPIO number for UART RX pin. See UART documentation for more information
|
||||
about available pin numbers for UART.
|
||||
@ -35,8 +36,9 @@ menu "Echo RS485 Example Configuration"
|
||||
default 23 if IDF_TARGET_ESP32
|
||||
range 0 46 if IDF_TARGET_ESP32S2
|
||||
default 20 if IDF_TARGET_ESP32S2
|
||||
range 0 48 if IDF_TARGET_ESP32S3
|
||||
range 0 19 if IDF_TARGET_ESP32C3
|
||||
default 4 if IDF_TARGET_ESP32C3
|
||||
default 4 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
help
|
||||
GPIO number for UART TX pin. See UART documentation for more information
|
||||
about available pin numbers for UART.
|
||||
@ -45,6 +47,7 @@ menu "Echo RS485 Example Configuration"
|
||||
int "UART RTS pin number"
|
||||
range 0 34 if IDF_TARGET_ESP32
|
||||
range 0 46 if IDF_TARGET_ESP32S2
|
||||
range 0 48 if IDF_TARGET_ESP32S3
|
||||
range 0 19 if IDF_TARGET_ESP32C3
|
||||
default 18
|
||||
help
|
||||
|
@ -9,7 +9,7 @@ and echoes it back to the monitoring console.
|
||||
|
||||
### Hardware Required
|
||||
|
||||
The example can be used with any ESP32 development board connected to a computer with a USB cable.
|
||||
The example can be used with any ESP32, ESP32-S and ESP32-C series based development board connected to a computer with a USB cable.
|
||||
|
||||
### Configure the project
|
||||
|
||||
|
@ -20,7 +20,7 @@ For a more comprehensive example please refer to `system/select`.
|
||||
|
||||
### Hardware Required
|
||||
|
||||
The example can be run on any ESP32 development board connected to a PC with a single USB cable for communication
|
||||
The example can be run on any ESP32, ESP32-S and ESP32-C series based development board connected to a computer with a single USB cable for communication
|
||||
through UART.
|
||||
|
||||
### Configure the project
|
||||
|
Loading…
x
Reference in New Issue
Block a user