Problem: ESP-S3-WROOM reboots when attempting to initialise Serial1/UART1.
Background:
This is my first programming project. I have tried to treat it as an educational project. The goal of the project is to mirror a relay state (HIGH/LOW) over the ModBus protocol to another set of relays.
I have prototyped it on a LOLIN S2 Mini board and all functions worked. I have then designed a prototype PCB with a ESP32-S3-WROOM 1 module.
IDE was in VSCode + PIO using the Arduino framework - no issues with the Lolin S2 Mini. Now using the Arduino IDE to allow easier setting of ESP32 options. It is connected via a USB to Serial adaptor (connected to the UART0 connections on the ESP32-S3, U0RXD pin 36 and U0TXD pin 37 respectively).
Link to ESP-S3-WROOM datasheet
Code:
#include <ModbusMaster.h>
#include <Arduino.h>
#include <driver/gpio_filter.h>
// initialise Modbus
ModbusMaster node;
// set RE/DE pin HIGH
#define RE_DE 38
// Define the digital input pins for the input relays
const int inputPins[] = {15, 17, 18, 19, 20};
// Define the MODBUS coil addresses for the relays
const int coilAddresses[] = {0x0000, 0x0001, 0x0002, 0x0003, 0x0004};
void setup()
{
// Initialise serial communication
Serial.begin(115200);
Serial.println("Initialised ESP32 serial.");
// Initialise serial connection for MODBUS
Serial1.begin(9600, SERIAL_8E1, 28, 31);
Serial.println("Initialised MODBUS serial.");
// set RE_DE pin to PULLUP as Tx only device
pinMode(RE_DE, INPUT_PULLUP);
// Initialize MODBUS
node.begin(255,Serial1);
Serial.println("Initialised MODBUS node.");
// Set input pins as input with internal pull-up resistors
for (int i = 0; i < 5; i++)
{
pinMode(inputPins[i], INPUT_PULLUP);
} // end input pin pull-up resistor routine.
for (int i = 0; i < 5; i++)
{
gpio_pin_glitch_filter_config_t config = {
.gpio_num = (gpio_num_t)inputPins[i]
};
gpio_glitch_filter_handle_t filter_handle;
gpio_glitch_filter_enable(filter_handle);
} //end glitch filter setup
Serial.println("Initial setup complete.");
}
void loop()
{
Serial.println("Begin polling pins.");
for (int i = 0; i < 5; i++)
{
int inputPin = inputPins[i];
int coilAddress = coilAddresses[i];
bool inputValue = digitalRead(inputPin) == HIGH;
bool valueToWrite = inputValue ? false : true; // Explicitly map HIGH to false and LOW to true
node.writeSingleCoil(coilAddress, valueToWrite);
Serial.println(String("Pin ") + i + " set to " + valueToWrite + ".");
}
}
Error messages (took me about half a day to work out that I need to turn verbose debugging on!)
08:58:40.399 -> =========== Before Setup Start ===========
08:58:40.399 -> Chip Info:
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> Model : ESP32-S3
08:58:40.399 -> Package : 0
08:58:40.399 -> Revision : 0.02
08:58:40.399 -> Cores : 2
08:58:40.399 -> CPU Frequency : 240 MHz
08:58:40.399 -> XTAL Frequency : 40 MHz
08:58:40.399 -> Features Bitfield : 0x00000012
08:58:40.399 -> Embedded Flash : No
08:58:40.399 -> Embedded PSRAM : No
08:58:40.399 -> 2.4GHz WiFi : Yes
08:58:40.399 -> Classic BT : No
08:58:40.399 -> BT Low Energy : Yes
08:58:40.399 -> IEEE 802.15.4 : No
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> INTERNAL Memory Info:
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> Total Size : 400572 B ( 391.2 KB)
08:58:40.399 -> Free Bytes : 369608 B ( 360.9 KB)
08:58:40.399 -> Allocated Bytes : 26140 B ( 25.5 KB)
08:58:40.399 -> Minimum Free Bytes: 364560 B ( 356.0 KB)
08:58:40.399 -> Largest Free Block: 327668 B ( 320.0 KB)
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> SPIRAM Memory Info:
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> Total Size : 8388608 B (8192.0 KB)
08:58:40.399 -> Free Bytes : 8385672 B (8189.1 KB)
08:58:40.399 -> Allocated Bytes : 576 B ( 0.6 KB)
08:58:40.399 -> Minimum Free Bytes: 8385672 B (8189.1 KB)
08:58:40.399 -> Largest Free Block: 8257524 B (8064.0 KB)
08:58:40.399 -> Bus Mode : OPI
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> Flash Info:
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> Chip Size : 16777216 B (16 MB)
08:58:40.399 -> Block Size : 65536 B ( 64.0 KB)
08:58:40.399 -> Sector Size : 4096 B ( 4.0 KB)
08:58:40.399 -> Page Size : 256 B ( 0.2 KB)
08:58:40.399 -> Bus Speed : 80 MHz
08:58:40.399 -> Bus Mode : QIO
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> Partitions Info:
08:58:40.399 -> ------------------------------------------
08:58:40.399 -> nvs : addr: 0x00009000, size: 20.0 KB, type: DATA, subtype: NVS
08:58:40.399 -> otadata : addr: 0x0000E000, size: 8.0 KB, type: DATA, subtype: OTA
08:58:40.399 -> app0 : addr: 0x00010000, size: 1280.0 KB, type: APP, subtype: OTA_0
08:58:40.399 -> app1 : addr: 0x00150000, size: 1280.0 KB, type: APP, subtype: OTA_1
08:58:40.399 -> spiffs : addr: 0x00290000, size: 1408.0 KB, type: DATA, subtype: SPIFFS
08:58:40.399 -> coredump : addr: 0x003F0000, size: 64.0 KB, type: DATA, subtype: COREDUMP
08:58:40.497 -> ------------------------------------------
08:58:40.497 -> Software Info:
08:58:40.497 -> ------------------------------------------
08:58:40.497 -> Compile Date/Time : Oct 4 2024 08:50:18
08:58:40.497 -> Compile Host OS : windows
08:58:40.497 -> ESP-IDF Version : v5.1.4-828-g33fbade6b8-dirty
08:58:40.497 -> Arduino Version : 3.0.5
08:58:40.497 -> ------------------------------------------
08:58:40.497 -> Board Info:
08:58:40.497 -> ------------------------------------------
08:58:40.497 -> Arduino Board : ESP32S3_DEV
08:58:40.497 -> Arduino Variant : esp32s3
08:58:40.497 -> Arduino FQBN : esp32:esp32:esp32s3:UploadSpeed=921600,USBMode=hwcdc,CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,CPUFreq=240,FlashMode=qio,FlashSize=16M,PartitionScheme=default,DebugLevel=verbose,PSRAM=opi,LoopCore=1,EventsCore=1,EraseFlash=all,JTAGAdapter=default,ZigbeeMode=default
08:58:40.497 -> ============ Before Setup End ============
08:58:40.626 -> [ 612][V][esp32-hal-uart.c:408] uartBegin(): UART0 baud(115200) Mode(800001c) rxPin(44) txPin(43)
08:58:40.626 -> [ 621][V][esp32-hal-uart.c:497] uartBegin(): UART0 not installed. Starting installation
08:58:40.626 -> [ 629][V][esp32-hal-uart.c:560] uartBegin(): UART0 initialization done.
08:58:40.626 -> Initialised ESP32 serial.
08:58:40.626 -> [ 636][V][esp32-hal-uart.c:408] uartBegin(): UART1 baud(9600) Mode(800001e) rxPin(28) txPin(31)
08:58:40.626 -> [ 647][V][esp32-hal-uart.c:497] uartBegin(): UART1 not installed. Starting installation
08:58:41.960 -> [ 88][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x42004510
08:58:41.960 -> [ 100][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x420044dc
08:58:41.960 -> [ 111][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x420044a8
08:58:41.960 -> [ 122][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x42004474
08:58:41.960 -> [ 134][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x42004510
08:58:41.960 -> [ 145][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x420044dc
08:58:41.960 -> [ 156][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x420044a8
08:58:41.960 -> [ 168][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x42004474
08:58:41.960 -> [ 179][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RX (2) successfully set to 0x42004510
08:58:41.960 -> [ 190][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_TX (3) successfully set to 0x420044dc
08:58:41.960 -> [ 201][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_CTS (4) successfully set to 0x420044a8
08:58:41.960 -> [ 213][V][esp32-hal-periman.c:235] perimanSetBusDeinit(): Deinit function for type UART_RTS (5) successfully set to 0x42004474
08:58:41.960 -> [ 225][I][esp32-hal-psram.c:90] psramInit(): PSRAM enabled
08:58:41.960 -> [ 235][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 44 successfully set to type UART_RX (2) with bus 0x3fc92800
08:58:41.960 -> [ 246][V][esp32-hal-periman.c:160] perimanSetPinBus(): Pin 43 successfully set to type UART_TX (3) with bus 0x3fc92800
08:58:41.960 -> =========== Before Setup Start ===========
My thoughts:
I included some serial printouts to try and work out where things were going wrong. I am probably wrong, but it seems that Serial0/UART0 initialised OK as the verbose output reports that initialization was 'OK' and I can see my serial printout. Then, Serial1/UART1 attempts to be started, but then the pins for Serial/UART0 are then assigned to the UART1 serial bus? (based upon the last two lines before the reboot occurs)
Many thanks for any assistance you can offer me.