invert status never reset on serial0 after having been set to invert once
mha1 opened this issue · comments
Board
esp32-s3-devkitc-1
Device Description
esp32-s3-devkitc-1
Hardware Configuration
Pin 3 (UART0 TX) and GND are connected to a logic analyzer.
Please refer to the test code below. Expected output is an alternating output of non-inverted and inverted serial signals.
For serial0 the logic analyzer trace shows non-inverted, inverted, inverted, ...
which is wrong.
running the test code on serial1 shows the expected behavior.
changing arduino-esp32/cores/esp32/esp32-hal-uart.c
fixes the problem however it is unclear why the serial0 and serial1 behave differently.
arduino-esp32/cores/esp32/esp32-hal-uart.c
Lines 517 to 520 in 99750cd
if (retCode && inverted) {
// invert signal for both Rx and Tx
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV);
}
else
{
// reset invert
retCode &= ESP_OK == uart_set_line_inverse(uart_nr, UART_SIGNAL_INV_DISABLE);
}
Version
latest master (checkout manually)
IDE Name
VSCode/platformio
Operating System
Windows 10
Flash frequency
40Mhz
PSRAM enabled
yes
Upload speed
921600
Description
It should be possible to change serial transmission from non-inverted to inverted and back to non-inverted. This doesn't work on serial0. Please refer to the test code I attached.
Sketch
#include <Arduino.h>
#include <HardwareSerial.h>
HardwareSerial serial(0); // use serial(1) for comparison
void setup() {}
void loop() {
serial.begin(115200, SERIAL_8N1, 3, 1, false);
serial.write("hello");
serial.flush();
serial.end();
serial.begin(115200, SERIAL_8N1, 3, 1, true);
serial.write("hello");
serial.flush();
serial.end();
}
Debug Message
see attached logic analyzer trace
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Yes, confirmed. Thank for the issue report, @mha1!
I'll add a PR as suggested.
About why Serial and Serial0 behave differently, I'll try to figure it out.