Hi all.
I knew it is not a good practice to use String in ESP32, just simply to do a test with these sketches:
one used String and one not, the String one output good result, and non String one got rebooting, I know this mean nothing, cause of they are simple small codes.
but why?
I have tried to use 'Backtrace: ' in esp32 exception decoder ', didn't get any results after paste the address into esp32 exception decode's window.
Thanks for help.
Adam
String code:
#include <SPI.h>
#include <SD.h>
const byte chipSelect = 10;
String parameter;
byte line;
String theArray[10];
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println("Initializing SD card...");
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present");
while (true);
}
Serial.println("card initialized.");
File myFile = SD.open("params.txt");
if (myFile)
{
while (myFile.available())
{
char c = myFile.read();
if (isPrintable(c))
{
parameter.concat(c);
}
else if (c == '\n')
{
// Serial.println(parameter);
theArray[line] = parameter;
parameter = "";
line++;
}
}
}
myFile.close();
printArray();
}
void loop()
{
}
void printArray()
{
Serial.println("\nThe array contains :\n");
for (int line = 0; line < 4; line++)
{
Serial.println(theArray[line]);
}
}
String code output:
17:55:25.928 -> The array contains :
17:55:25.928 ->
17:55:25.928 -> IPADDRESS = 192.168.1.1
17:55:25.928 -> SSID = WIFI1
17:55:25.928 -> PW = PASS1
17:55:25.928 -> NAME = MYNAME
non String code:
#include <SPI.h>
#include <SD.h>
char recordArray[4][30];
char aRecord[30];
byte recordNum;
byte charNum;
File myFile;
void setup()
{
Serial.begin(115200);
while (!Serial)
{
}
Serial.print("Initializing SD card...");
if (!SD.begin(10))
{
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("params.txt");
if (myFile)
{
Serial.println("params.txt:");
while (myFile.available())
{
char inChar = myFile.read();
if (inChar == '\n')
{
strcpy(recordArray[recordNum], aRecord);
recordNum++;
charNum = 0;
}
else
{
aRecord[charNum++] = inChar;
aRecord[charNum] = '\0';
}
}
myFile.close();
}
else
{
Serial.println("error opening params.txt");
}
printArray();
}
void loop()
{
}
void printArray()
{
Serial.println("from the array :");
for (int index = 0; index < 4; index++)
{
Serial.println(recordArray[index]);
}
}
non String code output:
18:06:35.605 -> Initializing SD card...initialization done.
18:06:35.605 -> params.txt:
18:06:35.605 -> Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
18:06:35.605 ->
18:06:35.605 -> Core 1 register dump:
18:06:35.605 -> PC : 0x4008a5b0 PS : 0x00060230 A0 : 0x800d1959 A1 : 0x3ffb1fd0
18:06:35.652 -> A2 : 0x000d7d98 A3 : 0xffffffff A4 : 0x000d7d98 A5 : 0x3ffb8dd8
18:06:35.652 -> A6 : 0x007bf328 A7 : 0x003fffff A8 : 0x800e4b18 A9 : 0x3ffb2110
18:06:35.652 -> A10 : 0x3ffc4d4c A11 : 0xffffffff A12 : 0x00000000 A13 : 0x3ffb805c
18:06:35.652 -> A14 : 0x00000002 A15 : 0x00000003 SAR : 0x0000001a EXCCAUSE: 0x0000001c
18:06:35.652 -> EXCVADDR: 0x000d7dd8 LBEG : 0x40086544 LEND : 0x4008654e LCOUNT : 0x00000000
18:06:35.652 ->
18:06:35.652 ->
18:06:35.652 -> Backtrace: 0x4008a5ad:0x3ffb1fd0 0x400d1956:0x3ffb2010 0x400d1c7f:0x3ffb2040 0x400d2031:0x3ffb2070 0x400e0d66:0x3ffb20a0 0x400e17ee:0x3ffb20c0 0x400e2c09:0x3ffb20e0 0x400e2cca:0x3ffb2110 0x400e4b15:0x3ffb2140 0x400de04f:0x3ffb2160 0x40086f4f:0x3ffb2180 0x4008570d:0x3ffb21a0 0x40085779:0x3ffb21d0 0x400d2bac:0x3ffb21f0 0x400d2b09:0x3ffb2210 0x400d1799:0x3ffb2240 0x400d5362:0x3ffb2290