Skip to content

Commit 6c6b909

Browse files
authored
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().
1 parent b25c1b2 commit 6c6b909

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cores/esp32/esp32-hal-uart.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,16 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
435435
if (retCode) retCode &= ESP_OK == uart_param_config(uart_nr, &uart_config);
436436

437437
// Is it right or the idea is to swap rx and tx pins?
438-
if (retCode && inverted) {
438+
if (retCode) {
439+
if (inverted) {
440+
// invert signal for both Rx and Tx
441+
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
442+
} else {
439443
// 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);
444+
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_INV_DISABLE);
445+
}
441446
}
442-
447+
// if all fine, set internal parameters
443448
if (retCode) {
444449
uart->_baudrate = baudrate;
445450
uart->_config = config;

0 commit comments

Comments
 (0)