This comm sketch simply read incoming bytes from the UART 1 where a device is attached. It works normally on a real Arduino device. But on ESP32, it makes it continuously reboot with the following messages:
([UPDATE] Note that there is no reboot on ESP32 is I use Serial2 instead of Serial1)
9:13:19.676 -> ets Jun 8 2016 00:22:57
19:13:19.676 ->
19:13:19.676 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
19:13:19.676 -> configsip: 0, SPIWP:0xee
19:13:19.676 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
19:13:19.676 -> mode:DIO, clock div:1
19:13:19.676 -> load:0x3fff0018,len:4
19:13:19.676 -> load:0x3fff001c,len:1216
19:13:19.714 -> ho 0 tail 12 room 4
19:13:19.714 -> load:0x40078000,len:10944
19:13:19.714 -> load:0x40080400,len:6388
19:13:19.714 -> entry 0x400806b4
19:13:19.786 -> Yo! from serial UART 18/19
19:13:19.786 -> SbmDi⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮@D@⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
@%cGuru Meditation Error: Core 1 panic'ed (IllegalInstruction). Exception was unhandled.
19:13:19.823 -> Memory dump at 0x400e90f4: ffffffff ffffffff ffffffff
19:13:19.823 -> Core 1 register dump:
19:13:19.823 -> PC : 0x400e90f8 PS : 0x00060530 A0 : 0x800d1529 A1 : 0x3ffb1f80
19:13:19.823 -> A2 : 0x3ffbfe88 A3 : 0x3ffbfe6c A4 : 0x0001c200 A5 : 0x0800001c
19:13:19.823 -> A6 : 0x00004e20 A7 : 0x00000000 A8 : 0x800d0c4f A9 : 0x3ffb1f60
19:13:19.857 -> A10 : 0x3ffbfe6c A11 : 0x3f40013b A12 : 0x0800001c A13 : 0x00000009
19:13:19.857 -> A14 : 0x00000009 A15 : 0x00000000 SAR : 0x00000016 EXCCAUSE: 0x00000000
19:13:19.857 -> EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffbd
19:13:19.857 ->
19:13:19.857 -> ELF file SHA256: 0000000000000000
19:13:19.857 ->
19:13:19.857 -> Backtrace: 0x400e90f8:0x3ffb1f80 0x400d1526:0x3ffb1fb0 0x400860ed:0x3ffb1fd0
19:13:19.891 ->
19:13:19.891 -> Rebooting...
Here's my code:
#include <Arduino.h>
#define SbmDisplaySerial Serial1
void setup() {
Serial.begin(115200);
//Serial.setDebugOutput(true);
Serial.println("Yo v0.0.1! from serial UART 18/19");
SbmDisplaySerial.begin(9600, SERIAL_8N1);//, 16, 17);
Serial.print("SbmDisplaySerial is ");
Serial.println(SbmDisplaySerial);
}
int _loop = 1;
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Loop #"); Serial.println(_loop++);
delay(1000);
if (!SbmDisplaySerial.available()) {
delay(2000);
Serial.println("No byte avail from the UART, looping…");
return;
}
int b = 0;
Serial.print("Synching with message limit (waiting for 0xA5 (165) header byte): ");
int i=0;
do {
delay(10);
b = SbmDisplaySerial.read();
Serial.print(b);
Serial.print(" ");
if (i%128==0) Serial.println();
i++;
}
while(b!=0xa5);
Serial.println("Ok, packet started!");
Serial.print("Received bytes: ");
Serial.print(b);
Serial.print(" ");
int soc = 0;
int voltage = 0;
int current = 0;
int capacity = 0;
for(int i=1; i<16; i++) {
b = SbmDisplaySerial.read()&0xff;
Serial.print(b);
Serial.print(" ");
switch(i) {
case 0: Serial.print("Header byte 0xA5");
voltage = 0;
current = 0;
capacity = 0;
break;
case 1: soc = b; Serial.print("(SoC: "); Serial.print(soc); Serial.print("%) "); break;
case 2: voltage = b<<8; break;
case 3: voltage |= b; Serial.print("("); Serial.print(float(voltage)*0.01); Serial.print("V) "); break;
case 4: capacity = b<<24; break;
case 5: capacity = b<<16; break;
case 6: capacity = b<<8; break;
case 7: capacity |= b; Serial.print("("); Serial.print(float(capacity)*0.001); Serial.print("A.h) "); break;
case 8: current = b<<24; break;
case 9: current = b<<16; break;
case 10: current = b<<8; break;
case 11: current |= b; Serial.print("("); Serial.print(float(current)*0.001); Serial.print("A) "); break;
//case 12: current = b<<8; break;
//case 13: current = b<<8; break;
//case 10: current |= b; Serial.print("(TOA: "); Serial.print(float(current)*0.001); Serial.print("Seconds) "); break;
}
if (!SbmDisplaySerial.available()){
delay(2000);
Serial.print(" No more byte prior reaching 16 bytes, looping…");
break;
}
}
Serial.println("Waiting for next packet");
delay(10000);
}
[UPDATE] When ran on Arduino, I get typical logs as follows:
11:20:18.217 -> Yo v0.0.1! from serial UART 18/19
11:20:18.217 -> SbmDisplaySerial is 1
11:20:18.217 -> Loop #1
11:20:19.204 -> Synching with message limit (waiting for 0xA5 (165) header byte): 0
11:20:19.204 -> 0 0 0 0 165 Ok, packet started!
11:20:19.275 -> Received bytes: 165 28 (SoC: 28%) 4 251 (12.75V) 0 0 54 248 (14.07A.h) 255 255 0 0 (0.00A) 0 0 0 0 Waiting for next packet
11:20:29.263 -> Loop #2
11:20:30.266 -> Synching with message limit (waiting for 0xA5 (165) header byte): 0
11:20:30.266 -> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 165 Ok, packet started!
11:20:30.508 -> Received bytes: 165 28 (SoC: 28%) 4 251 (12.75V) 0 0 182 0 (46.59A.h) 0 0 0 0 (0.00A) 0 0 0 0 Waiting for next packet
Serial.println(SbmDisplaySerial);
how is that supposed to work?Serial.println()
statement out and see if it makes a difference?