mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ef5dc73f6f
An existing UART driver does not support RS485 half duplex mode. This task adds this functionality to ESP_IDF UART driver. driver/uart.c/h: updated to add support of RS485 half duplex mode examples/peripherals/uart_echo_rs485/main/rs485_example.c: added test example components/driver/test/test_uart.c: added test of RS485 half duplex mode docs/en/api-reference/peripherals/uart.rst: updated documentation test_uart.c: suppress GCC warnings about discarded const qualifiers uart.rst: remove sphinx warning - "Duplicate explicit target name" simple change in uart.h file update (test_uart.c) after rebase from master update uart.rst, uart.c, rs485_example.c Update example description in file Readme.md update uart.c/h, uart.rst, test_uart.c according to review results update uart.h (uart_set_rx_timeout() description test_uart.c remove ignore tag uart.c/h: fix param errors test_uart.c: Remove GCC warning supress uart.rst: fix the notes rs485_example.c: fix output The tests are completed using RS485 adapters hardware connected to two ESP32 WROVER KITs. TW#13812 Closes https://github.com/espressif/esp-idf/pull/667 Closes https://github.com/espressif/esp-idf/pull/1006 |
||
---|---|---|
.. | ||
main | ||
Makefile | ||
README.md |
UART RS485 Echo Example
This is an example which echoes any data it receives on UART2 back to the sender.
Setup
This example uses external RS485 interface. The MAX485 line driver can be used for example.
RS485 example connection circuit schematic:
VCC ---------------+ +--------------- VCC
| |
+-------x-------+ +-------x-------+
RXD <------| RO | | RO|-----> RXD
| B|---------------|B |
TXD ------>| DI MAX485 | \ / | MAX485 DI|<----- TXD
ESP32 WROVER KIT | | RS-485 side | | SERIAL ADAPTER RTS --+--->| DE | / \ | DE|---+ | | A|---------------|A | | +----| /RE | | /RE|---+-- RTS +-------x-------+ +-------x-------+ | | --- ---
- Connect an external RS485 serial interface to an ESP32 board.
| ESP32 Interface | #define | ESP32 Pin | External RS485 | | ----------------------|---------------|-----------| Driver Pin | | Transmit Data (TxD) | ECHO_TEST_TXD | GPIO23 | DI | | Receive Data (RxD) | ECHO_TEST_RXD | GPIO22 | RO | | Request To Send (RTS) | ECHO_TEST_RTS | GPIO18 | ~RE/DE | | Ground | n/a | GND | GND |
- Connect USB to RS485 adapter to computer and connect its D+, D- output lines with the D+, D- lines of RS485 driver connected to ESP32.
- Compile and load the example to the ESP32 board
- Refer to the example and set up a serial terminal program to the same settings as of UART in ESP32
- Open the external serial interface in the terminal.
- By default if no any symbols 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. There should be no any "." once TxD pin is disconnected.