Difference between ESP32S2 and esp32s3

I have the following code example:

#define RXD2 16
#define TXD2 17

void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200);
  //Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial.println("Serial Txd is on pin: "+String(TX));
  Serial.println("Serial Rxd is on pin: "+String(RX));
}

void loop() { //Choose Serial1 or Serial2 as required
  while (Serial2.available()) {
    Serial.print(char(Serial2.read()));
  }
}

Which successfully compiles for an adafruit feather esp32s3 but does NOT compile for the esp32s2. I get the following error for the esp32s2:

error: 'Serial2' was not declared in this scope

I can make it compile in a few ways but the only way I can get it to work is:

  • Finding and replacing all instances of Serial2 with Serial1

I figured that out by trial and error, and I am not sure I understand the issue I ran into and whether this is the best fix for it. Does anyone here have any insight?

Seems like one has 3 UARTs, the other has 2. Hence, Serial, Serial1, Serial2, vs Serial, Serial1.

https://docs.espressif.com/projects/esp-idf/en/v5.0.2/esp32s3/hw-reference/chip-series-comparison.html
But, I'm no ESP expert, I just googled a comparison from Espressif

The S2 only has 2 UARTs, so expect them to be Serial and Serial1.

The ESP32 S2 has 2 uart plus the internal usb.
The ESP32 has 3 uart no internal usb.
Note internal USB is not a hardware uart.

ESP32S2 second hardware uart does not work with arduino ide, this is a bug.

We can use usb and both uart by circumventing arduino serial and using espressif libraries. This:

#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));  
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.