Page 1 of 1

ESP32 S2 serial2 not working

Posted: Mon May 06, 2024 5:35 am
by PepeTheGreat
The S2 has usb plus 2 hardware uart.
Serial usb
Serial1 = hardware first
Serial2 = hardware second

Arduino IDE:
  1. void setup()
  2. {
  3.   Serial1.begin(9600,SERIAL_8N1,13,12);
  4.   Serial2.begin(4800,SERIAL_8N1,10,11);
  5. }
  6.  
  7.  
  8. void loop()
  9. {
  10.   Serial1.println("hello 1");
  11.   Serial2.println("hello 2");
  12.   delay(100);  
  13. }
gives compile error "'Serial2' was not declared in this scope"

Re: ESP32 S2 serial2 not working

Posted: Mon May 06, 2024 5:42 am
by PepeTheGreat
This compiles, has outpunt on pin 12 but no output pin 11

Code: Select all

#include <hardwareserial.h>
HardwareSerial Seriala(1);
HardwareSerial Serialb(2);

void setup() 
{
  Seriala.begin(9600,SERIAL_8N1,13,12);
  Serialb.begin(4800,SERIAL_8N1,10,11);
}


void loop() 
{
  Seriala.println("hello 1");
  Serialb.println("hello 2");
  delay(100);   
}
Output tested on 2-chan oscilloscope.

Re: ESP32 S2 serial2 not working

Posted: Mon May 06, 2024 6:34 am
by lbernstone
They start counting at zero. Serial == Serial0 (aka the default console). Serial1 == HardwareSerial(1)

Re: ESP32 S2 serial2 not working

Posted: Mon May 06, 2024 7:02 am
by PepeTheGreat
Serial == Serial0 (aka the default console). <-- not hardwareserial, but USB
Serial1 == HardwareSerial(1)
Serial2 == HardwareSerial(2) <-- this one not working in arduino ide

I interpret "2 uart" as "2 hardwareserial".
See "uart" here:
https://docs.espressif.com/projects/esp ... rison.html
or doc here – 2 × UART
https://www.espressif.com/sites/default ... eet_en.pdf

Does the S2 have only one hardwareserial?

Re: ESP32 S2 serial2 not working

Posted: Mon May 06, 2024 4:47 pm
by lbernstone
There are two UART devices- 0 & 1. UART0 (Serial0) is still attached to console at boot, even if you are using HWCDC. This means that you would need to burn the UART_PRINT_CONTROL eFuse if the boot messages will interrupt your device on that port.

Re: ESP32 S2 serial2 not working

Posted: Mon May 06, 2024 9:42 pm
by PepeTheGreat
Me thinks console, serial0, is not uart but usb.

I did read with esp-idf both serial do work. Seems an arduino-ide problem.

Re: ESP32 S2 serial2 not working

Posted: Tue May 07, 2024 12:07 am
by lbernstone
You are, quite simply, incorrect.
If you have an S3 devkit with both UART and USB, you can test this easily. Set CDC On Boot to enabled, and run the following (requires v3.0.0). You will get different prints on the different ports.

Code: Select all

void setup() {
  Serial0.begin(115200);
  Serial.begin(9600);
  Serial1.begin(115200);
}

void loop() {
  if (HWCDCSerial) Serial.println("Testing USB");
  Serial0.println("Testing UART0");
  Serial1.println("Testing UART1");
  delay(1000);
}

Re: ESP32 S2 serial2 not working

Posted: Tue May 07, 2024 9:36 am
by PepeTheGreat
How do you explain this works?

Code: Select all

#include "driver/uart.h"

// ESP32S2 usb cdc on boot on, usb dfu on boot off, upload mode internal usb.

const int VEBUS_RXD1=13, VEBUS_TXD1=12;  
const int VEBUS_RXD2=10, VEBUS_TXD2=11;  

const int UART_USED1 = 0; //UART_NUM_1; // serial1
const int UART_USED2 = 1; // serial2

const int LED = 15;

esp_err_t err11,err12,err13,err21,err22,err23;

void setup() 
{
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  Serial.begin(115200);
  delay(5000);
  Serial.println("Start");

  uart_config_t uart_config1 = 
  {
        .baud_rate = 9600,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_EVEN,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, 
        .rx_flow_ctrl_thresh = 32,
  };
  err11 = uart_driver_install(UART_USED1, 256, 256, 0, NULL, 0);
  err12 = uart_param_config(UART_USED1, &uart_config1);   
  err13 = uart_set_pin(UART_USED1, VEBUS_TXD1, VEBUS_RXD1, -1, -1);

  Serial.println(err11);
  Serial.println(err12);
  Serial.println(err13);
  
  uart_config_t uart_config2 = 
  {
        .baud_rate = 9600,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_EVEN,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, 
        .rx_flow_ctrl_thresh = 32,
  };
  err21 = uart_driver_install(UART_USED2, 256, 256, 0, NULL, 0);
  err22 = uart_param_config(UART_USED2, &uart_config2);   
  err23 = uart_set_pin(UART_USED2, VEBUS_TXD2, VEBUS_RXD2, -1, -1);
  
  Serial.println(err21);
  Serial.println(err22);
  Serial.println(err23);

  Serial.println("Done");
}

char buf1[3] = { 0xaF, 0x00, 0x55 };
char buf2[3] = { 0xa0, 0xFF, 0x55 };

void loop() 
{
  uart_write_bytes(UART_USED1, buf1, 3);
  buf1[2]++;
  uart_write_bytes(UART_USED2, buf2, 3);
  buf2[2]++;
  delay(100);   
  digitalWrite(LED, !digitalRead(LED));  
}
usb output

Code: Select all

Start
0
0
0
0
0
0
Done
This shows two hardware UART and the usb console working by circumnavigating the arduino functions.
"You are, quite simply, incorrect."

pic measured pin 11 and 12

Re: ESP32 S2 serial2 not working

Posted: Thu May 09, 2024 3:23 pm
by PepeTheGreat
I wonder if this will be corrected or if arduino usesrs will be limited to one serial on the ESP32S2 for eternity?