Cannot receive data from UART1 and UART2

Angle Gao
Posts: 3
Joined: Sat Jun 04, 2022 7:06 am

Cannot receive data from UART1 and UART2

Postby Angle Gao » Sat Jun 04, 2022 7:13 am

Dear members,

I am trying to test Hardware UART function on a ESP32 module base on Arduino.
An USB -UART dongle was use to test the ESP32. below is the code.
RX on UART0 can receive the data send from dongle.
but the UART1 and UART2 can't receive data. however, trasnfer from TX works well.



HardwareSerial UART2(2);
void setup() {
UART2.begin(115200, SERIAL_8N1, 16,17,false,20000);
delay(500);
Serial.begin(115200);
delay(100);
Serial.println("UART0 was activated");

delay(200);
UART2.println("UART2 OUTPUT");

}
int i;
String Data;
void loop() {
delay(1000);

i = UART2.available();
UART2.println(i);
if(i>0){
while(i){
i--;

Data = Data + UART2.read();

}
UART2.print(Data);
Data="";
}

}

Angle Gao
Posts: 3
Joined: Sat Jun 04, 2022 7:06 am

Re: Cannot receive data from UART1 and UART2

Postby Angle Gao » Mon Jun 06, 2022 1:06 am

I have fixed the problem.
UART0, UART1, UART2 is default name in HardwareSerial.h
it should be be used as a class name for UART. the name of UART was changed to DebugUart and everything works well.

Hardwareserial DebugUart(1);

Who is online

Users browsing this forum: No registered users and 61 guests