Skip to content

Commit dccd37e

Browse files
Jason2866SuGlider
andauthored
Fix: uart invert polarity 2.x (#449)
* fix(uart): Set back Pin signal polarity Fixes a problem related to inverting signal polarity back to normal after a previous inversion. This shall set the correct polarity in Serial.begin(). --------- Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
1 parent 24184f7 commit dccd37e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cores/esp32/esp32-hal-uart.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,16 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
434434

435435
if (retCode) retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config);
436436

437-
// Is it right or the idea is to swap rx and tx pins?
438-
if (retCode && inverted) {
437+
if (retCode) {
438+
if (inverted) {
439+
// invert signal for both Rx and Tx
440+
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
441+
} else {
439442
// invert signal for both Rx and Tx
440-
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
443+
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_INV_DISABLE);
444+
}
441445
}
442-
446+
// if all fine, set internal parameters
443447
if (retCode) {
444448
uart->_baudrate = baudrate;
445449
uart->_config = config;

0 commit comments

Comments
 (0)