ESP32-C3 serial1 not working

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

ESP32-C3 serial1 not working

Postby eliott » Wed Aug 11, 2021 2:29 pm

Hello,

I'm trying to use the second serial port on my new ESP32-C3-WROOM-02 board.

The main port UART0 is OK and I bootload the program from Arduino IDE, and I receive debug informations.

GPIO are working well to, I only need to send data from UART1 to finish my project !

The project source is from BLE_uart code example. I only added few features because all the logic comme from BT app, but the following lines doesn't do anythings:

Code: Select all


//header
#define RX1 2
#define TX1 3

//setup()
Serial1.begin(115200, SERIAL_8N1, RX1, TX1);
Serial1.println("BOOT");

//function
class MyCallbacks: public BLECharacteristicCallbacks {
    void onWrite(BLECharacteristic *pCharacteristic) {
      std::string rxValue = pCharacteristic->getValue();

      if (rxValue.length() >= 6)
      {
        g_count_total_rx++;
        Serial.print("Received Value: ");

        char l_buffer[20] = {0};

        for (int i = 0; i < 6; i++)
        {
          Serial.print(rxValue[i], DEC);
          if(i<(rxValue.length()-1)) Serial.print("-");
        }

        Serial.println("");
        if(rxValue[0]==0xD0 && rxValue[5]==0xFF)
        {
            g_time_deep_sleep = 5000;                             //5 secondes
            g_timer_shutdown = 0;                                 //pour mettre à jour après la déco
            Serial.println("Entering deep speel mode");           //affichage sur la console
        }
        else
        {
          char l_buffer[20] = {0};
          for (int i = 0; i < 6; i++) Serial1.print(rxValue[i]);  //envoi à l'ECU
          sprintf(l_buffer, "Count %u\r\n", g_count_total_rx);
          bletx(l_buffer, strlen(l_buffer));                      //en onvoi le compre à l'appli
          Serial.print(l_buffer);                                 //affichage du comte sur la console
        }
      }
    }
};
So with this function I'm supposed to receive the raw data from bluetooth on my serial port:

This line is supposed to send data:

Code: Select all

 for (int i = 0; i < 6; i++) Serial1.print(rxValue[i]);
I receive the decimal content on the debug port, I see message counter "Serial.print(l_buffer);"

I tested to switch RX & TX pins, monitored with FTDI device or scope. The elecical level ar OK (3V3 for TX) so the port seems to be great configured.

I use the last https://raw.githubusercontent.com/espre ... index.json lib version 2.0.0-rc1

Thank you for help.

Eliott.

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: ESP32-C3 serial1 not working

Postby eliott » Wed Aug 11, 2021 3:39 pm

Hello,

I started new projet from scratch.

With Arduino IDE this code doesn't work (GetChipID example code)

Code: Select all


void setup() {
	Serial.begin(115200);
  Serial1.begin(115200,SERIAL_8N1,3,2);
  //Serial1.begin(115200,SERIAL_8N1,2,3);//tried both
}

void loop() {
	for(int i=0; i<17; i=i+8) {
	  chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
	}

	Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
	Serial.printf("This chip has %d cores\n", ESP.getChipCores());
  Serial.print("Chip ID: "); Serial.println(chipId);
  Serial1.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
  Serial1.printf("This chip has %d cores\n", ESP.getChipCores());
  Serial1.print("Chip ID: "); Serial.println(chipId);  
	delay(3000);

}
With Espressif SDK ESP32-C3, the uart_echo code works with UART 1 on PIN 2/3:

Code: Select all

/* UART Echo Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

/**
 * This is an example which echos any data it receives on configured UART back to the sender,
 * with hardware flow control turned off. It does not use UART driver event queue.
 *
 * - Port: configured UART
 * - Receive (Rx) buffer: on
 * - Transmit (Tx) buffer: off
 * - Flow control: off
 * - Event queue: off
 * - Pin assignment: see defines below (See Kconfig)
 */

#define ECHO_TEST_TXD (CONFIG_EXAMPLE_UART_TXD)
#define ECHO_TEST_RXD (CONFIG_EXAMPLE_UART_RXD)
#define ECHO_TEST_RTS (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS (UART_PIN_NO_CHANGE)

#define ECHO_UART_PORT_NUM      (CONFIG_EXAMPLE_UART_PORT_NUM)
#define ECHO_UART_BAUD_RATE     (CONFIG_EXAMPLE_UART_BAUD_RATE)
#define ECHO_TASK_STACK_SIZE    (CONFIG_EXAMPLE_TASK_STACK_SIZE)

#define BUF_SIZE (1024)

static void echo_task(void *arg)
{
    /* Configure parameters of an UART driver,
     * communication pins and install the driver */
    uart_config_t uart_config = {
        .baud_rate = ECHO_UART_BAUD_RATE,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_APB,
    };
    int intr_alloc_flags = 0;

#if CONFIG_UART_ISR_IN_IRAM
    intr_alloc_flags = ESP_INTR_FLAG_IRAM;
#endif

    ESP_ERROR_CHECK(uart_driver_install(ECHO_UART_PORT_NUM, BUF_SIZE * 2, 0, 0, NULL, intr_alloc_flags));
    ESP_ERROR_CHECK(uart_param_config(ECHO_UART_PORT_NUM, &uart_config));
    ESP_ERROR_CHECK(uart_set_pin(ECHO_UART_PORT_NUM, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS));

    // Configure a temporary buffer for the incoming data
    uint8_t *data = (uint8_t *) malloc(BUF_SIZE);

    while (1) {
        // Read data from the UART
        int len = uart_read_bytes(ECHO_UART_PORT_NUM, data, BUF_SIZE, 20 / portTICK_RATE_MS);
        // Write data back to the UART
        uart_write_bytes(ECHO_UART_PORT_NUM, (const char *) data, len);
    }
}

void app_main(void)
{
    xTaskCreate(echo_task, "uart_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
}

SDK config:

#
# Echo Example Configuration
#
CONFIG_EXAMPLE_UART_PORT_NUM=1
CONFIG_EXAMPLE_UART_BAUD_RATE=115200
CONFIG_EXAMPLE_UART_RXD=2
CONFIG_EXAMPLE_UART_TXD=3
CONFIG_EXAMPLE_TASK_STACK_SIZE=2048
# end of Echo Example Configuration

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: ESP32-C3 serial1 not working

Postby eliott » Thu Aug 12, 2021 6:03 pm

Last test:

OK:

Code: Select all

  char ltmp[20];
  sprintf(ltmp,"UART1 ready\r\n");

  uart_t* p_uart = uartBegin(0, 115200, SERIAL_8N1 , 2, 3, 100, 0, 122);
  uartWriteBuf(p_uart, (uint8_t*)ltmp, 12);

  Serial.println("Waiting a client connection to notify...");
[ 624][E][esp32-hal-cpu.c:107] addApbChangeCallback(): duplicate func=42008482 arg=3FC8D2CC<CR><LF>
UART1 ready
Waiting a client connection to notify...<CR><LF>
NOK:

char ltmp[20];
sprintf(ltmp,"UART1 ready\r\n");

uart_t* p_uart = uartBegin(1, 115200, SERIAL_8N1 , 2, 3, 100, 0, 122);
uartWriteBuf(p_uart, (uint8_t*)ltmp, 12);

Serial.println("Waiting a client connection to notify...");

drmpf321
Posts: 9
Joined: Thu Dec 10, 2015 10:33 pm

Re: ESP32-C3 serial1 not working

Postby drmpf321 » Fri Apr 29, 2022 6:01 am

Code: Select all

// ESP32 C3 SERIAL1  (second Uart)
void setup() {
   Serial.begin(115200);
   Serial1.begin(115200,SERIAL_8N1, 4,5); //int8_t rxPin=4, int8_t txPin=5 
}

void loop() {
    if (Serial.available()) {      // If anything comes in Serial (USB),
    Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 4 & 5)
  }

  if (Serial1.available()) {     // If anything comes in Serial1 (pins 4 & 5)
    Serial.write(Serial1.read());   // read it and send it out Serial (USB)
  }
}
works for me on ESP32 C3

calvsg88
Posts: 10
Joined: Tue Aug 09, 2022 7:54 am

Re: ESP32-C3 serial1 not working

Postby calvsg88 » Mon Jan 02, 2023 4:09 am

Hi,

I'm using Arduino IDE and 'ESP32-C3-WROOM-02-N4.

I can't get UART1 no matter which pins I used.

Anyone managed to get it to work on Arduino IDE?

JeanRiegardt
Posts: 1
Joined: Fri Aug 25, 2023 8:05 am

Re: ESP32-C3 serial1 not working

Postby JeanRiegardt » Fri Aug 25, 2023 8:19 am

Hi

Sorry for the late reply. I am busy with a new design for which I have selected the ESP32-C3-WROOM-02 and need two serial ports. I found you post earlier this week. Based on it I purchased a module and built it up to test with some code I found above by drmpf321 » Fri Apr 29, 2022 8:01 am and both UART channels are working. I do use Aduino IDE 2.1.0 with "ESP32C3 Dev Module"

My circuit consists of just the module with a pull up resistor on GPIO8 and another one one the enable pin. I'm not sure about the "N4" suffix but here is the exact module I used

https://www.robotics.org.za/ESP32-C3-WR ... esp32%20c3

Who is online

Users browsing this forum: Google [Bot] and 90 guests