-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Serial1.setPins not working on ESP32-S3 #8755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
please use it this way (set the RTS Pins, set Hardware Flow Control to activate CTS/RTS control, set the RS485 Mode) void setup() {
Serial.begin(9600);
Serial1.begin(9600,SERIAL_8N1,13,11,false,500,112);//works, but I cannot assign RTS pin
if (!Serial1.setPins(-1, -1, -1, 12)) Serial.println("Failed setting RTS pin!"); // just assigns RTS pin.
// UART_HW_FLOWCTRL_CTS_RTS or only UART_HW_FLOWCTRL_CTS | UART_HW_FLOWCTRL_RTS
// UART_HW_FLOWCTRL_DISABLE to disable Hardware Control on UART
// 64 is the Threshold for RX Flow control when RTS is used. It goes from 0 to 127 (bytes).
if (!Serial1.setHwFlowCtrlMode(UART_HW_FLOWCTRL_RTS, 64))
Serial.println("Failed changing Flow Control from Software to Hardware RTS!"); // use RTS only instead of xon/xoff
//I need RTS for RS-485 mode
if (!Serial1.setMode(MODE_RS485_HALF_DUPLEX)) Serial.println("Failed setting RS485 Mode");
}
void loop() {
if (Serial1.available()) {
int bait = Serial1.read();
Serial.println(bait);
}
} arduino-esp32/cores/esp32/HardwareSerial.h Lines 162 to 168 in d048e21
|
Hi. I couldn't compile it with "if (!Serial1.setHwFlowCtrlMode(UART_HW_FLOWCTRL_RTS, 64)) " E (4383) uart: uart_set_mode(1729): disable hw flowctrl before using RS485 mode I think this setPins issue should be listed as bug. Edit: Your solution does not work anyway even without the MODBUS mode thing: Serial1.begin(9600,SERIAL_8N1,13,11,false,500,112); |
@Erklei - I tried these 2 examples with the ESP32-S3: Example 1 - Uses Serial Monitor to send data to Serial, read it and print it back(don't forget to set Serial Monitor to 9600 baud) void setup() {
Serial.begin(9600, SERIAL_8N1, -1, -1, false, 500, 112);
Serial.println("Started.");
Serial.setPins(-1, -1, -1, 5); // sets RTS Pin only
}
void loop() {
if (Serial.available() > 0) {
Serial.print((char)Serial.read());
}
delay(50);
} Example 2 - Cross connect Serial1 RX pin (13) with Serial TX pin. It executes by itself.(don't forget to set Serial Monitor to 115200 baud to see the results) void setup() {
Serial.begin(115200, SERIAL_8N1);
// RX 13 -- TX 11
Serial1.begin(115200,SERIAL_8N1,13,11,false,500,112);//works, but I cannot assign RTS pin
// Both of these next 2 lines works fine!
//Serial1.setPins(13, 11, -1, 12); //Does not work, but I need to assign RTS pin.
Serial1.setPins(-1, -1, -1, 12); //Does not work, but I need to assign RTS pin.
//Serial1.setMode(MODE_RS485_HALF_DUPLEX);//I need RTS for RS-485 mode
delay(100);
Serial.println("Started.");
// waits Serial to send all its data
delay(100);
// a lot of data has been sent to Serial1 RX by Serial TX in boot.
while (Serial1.available()) Serial1.read(); // just ignores the last sent data
}
void loop() {
if (Serial1.available()) {
char bait = Serial1.read() + 1; // next letter A->B
Serial.println(bait); // sends "B\r\n" to Serial Monitor and Serial1
delay(100);
// consumes the 3 chars just sent to Serial1 by cross connection
bool ERR = false;
char ch = Serial1.read();
if (ch != 'B') {
Serial.println();
Serial.println((int) ch);
ERR = true;
}
ch = Serial1.read();
if (ch != '\r') {
Serial.println();
Serial.println((int) ch);
ERR = true;
}
ch = Serial1.read();
if (ch != '\n') {
Serial.println();
Serial.println((int) ch);
ERR = true;
}
if (ERR) {
Serial.println("\n===> ERRROR reading Serial1!");
while(1); // halts execution.
}
}
// send 'A' to be read by Serial1 in the cross connections TX0->RX1
Serial.print('A');
delay(500);
} Output of the Example2:
|
Example 2 works also when |
Please make sure you are using Arduino Core 2.0.14 |
The error in compilation is due to the settings that are using the USB CDC, not the UART as Set "USB CDC On Boot" to "Disable" and then |
Ok, got it working correctly after disabling USB. In summary:
|
Board
ESP32-S3
Device Description
Custom board with ESP32-S3
Hardware Configuration
custom board, hardware checked and good.
Version
v2.0.14
IDE Name
Arduino IDE 2.2.1
Operating System
Win10
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
921600 through USB CDC
Description
Serial1 pins can be assigned using begin(rx,tx etc
But I need to assign also RTS pin.
If I use Serial1.setPins, it looses Rx assignment. TX and RTS assignment are kept correct.
I test it by commenting or uncommenting Serial1.setPins function after Serial1.begin
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: