ESP32 Guru Meditation Error: Core 1 panic’ed

Hello, there I am using ESP32 dev board and I program it with Arduino IDE. On the serial monitor, I get the error I wrote in the title. When I searched the internet, I saw that many people got this error. But I couldn't find a solution. I am sharing my source code and the screenshot of the error I got below.

#include <Arduino.h>

#define Rx2 16
#define Tx2 17

const uint8_t requestSize = 3;
const uint8_t recievedSize = 9;
uint8_t request[requestSize];
uint8_t recievedData[recievedSize];
uint8_t recieveCount;

long int t = 0x0000;
long int f = 0x000000;

float temperature, flow;
int bufferSizeCount = 0;

uint8_t Checksum();
void Flow_N_Temperature();
void Flow_N_Temperature_HEX();

void setup() 
{
  Serial.begin(38400);
  Serial2.begin(38400, SERIAL_8N1, Rx2, Tx2);
  while(!Serial);
  while(!Serial2);
  request[0] = 0xFF; 
}

void loop() 
{
  Flow_N_Temperature();
  //Flow_N_Temperature_HEX();
}

uint8_t Checksum()
{
  uint8_t sum = 0;
  for (uint8_t i = 1; i < (requestSize - 1); i++)
  {
    sum += request[i];
  }
  return sum;
}

void Flow_N_Temperature()
{
  request[1] = 0xC0;
  request[2] = Checksum();
  Serial2.write(request, requestSize);
  delay(100);
  while(Serial2.available() < 5);
  uint16_t data = Serial2.read();
  recievedData[recieveCount] = data;
  recieveCount++;
  if (recieveCount == 2)
  {
    if ((recievedData[1] == 0x8D) || (recievedData[1] == 0x8F))
    {
      bufferSizeCount = 1; //Total Byte = 9
    }

    if ((recievedData[1] == 0x89) || (recievedData[1] == 0x8B))
    {
      bufferSizeCount = 2; //Total Byte = 8
    }
  }

  if ((recieveCount == 9) && (bufferSizeCount == 1))
  {
    long int f2 = recievedData[2] << 16;
    long int f1 = recievedData[3] << 8;
    long int f0 = recievedData[4] << 0;
    f = f2 + f1 + f0;
    flow = (float)f / 1000; //Akış değeri için HEX değeri 1000'e böl

    long int t1 = recievedData[6] << 8;
    long int t0 = recievedData[7] << 0;
    t = t1 + t0;
    temperature = (float)t / 10;

    Serial.println("-------------------------------");
    Serial.print("Temp: ");
    Serial.print(temperature);
    Serial.println(" °C");
    Serial.println("-------------------------------");
    Serial.print("Flow: ");
    Serial.print(flow);
    Serial.println(" lt/dk");
    Serial.println("-------------------------------");
    Serial.println();
    recieveCount = 0;
    bufferSizeCount = 0;
  }

  if ((recieveCount == 8) && (bufferSizeCount == 2))
  {
    long int f2 = recievedData[2] << 16;
    long int f1 = recievedData[3] << 8;
    long int f0 = recievedData[4] << 0;
    f = f2 + f1 + f0;
    flow = (float)f / 1000; //Akış değeri için HEX değeri 1000'e böl

    long int t1 = recievedData[5] << 8;
    long int t0 = recievedData[6] << 0;
    t = t1 + t0;
    temperature = (float)t / 10;

    Serial.println("-------------------------------");
    Serial.print("Temp: ");
    Serial.print(temperature);
    Serial.println(" °C");
    Serial.println("-------------------------------");
    Serial.print("Flow: ");
    Serial.print(flow);
    Serial.println(" lt/dk");
    Serial.println("-------------------------------");
    Serial.println();
    recieveCount = 0;
    bufferSizeCount = 0;
  } 
}

void Flow_N_Temperature_HEX()
{
  request[1] = 0xC0;
  request[2] = Checksum();
  Serial2.write(request, requestSize);
  for (int i = 0; i < requestSize; i++)
  {
    Serial.print("Request Data ");
    Serial.print(i);
    Serial.print(": 0x");
    Serial.println(request[i], HEX);
    Serial.println("-------------------------------");
  }
  Serial.println();
  
  while(Serial2.available() < 5);
  uint16_t data = Serial2.read();
  recievedData[recieveCount] = data;
  Serial.println("-------------------------------");
  Serial.print("***Recieve Byte ");
  Serial.print(recieveCount);
  Serial.print(": 0x");
  Serial.println(recievedData[recieveCount], HEX);
  Serial.println("-------------------------------");
  Serial.println();
  delay(1000);
  recieveCount++;
  if (recieveCount == 2)
  {
    if ((recievedData[1] == 0x8D) || (recievedData[1] == 0x8F))
    {
      bufferSizeCount = 1; //Total Byte = 9
    }

    if ((recievedData[1] == 0x89) || (recievedData[1] == 0x8B))
    {
      bufferSizeCount = 2; //Total Byte = 8
    }
  }

  if ((recieveCount == 9) && (bufferSizeCount == 1))
  {
    long int f2 = recievedData[2] << 16;
    long int f1 = recievedData[3] << 8;
    long int f0 = recievedData[4] << 0;
    f = f2 + f1 + f0;
    flow = (float)f / 1000; //Akış değeri için HEX değeri 1000'e böl

    long int t1 = recievedData[6] << 8;
    long int t0 = recievedData[7] << 0;
    t = t1 + t0;
    temperature = (float)t / 10;

    Serial.print("Temp Hex: ");
    Serial.println(t);
    Serial.println("-------------------------------");
    Serial.print("Flow HEX: ");
    Serial.println(f);
    Serial.println("-------------------------------");
    Serial.println();
    Serial.println("-------------------------------");
    Serial.print("Temp: ");
    Serial.print(temperature);
    Serial.println(" °C");
    Serial.println("-------------------------------");
    Serial.print("Flow: ");
    Serial.print(flow);
    Serial.println(" lt/dk");
    Serial.println("-------------------------------");
    Serial.println();
    recieveCount = 0;
    bufferSizeCount = 0;
    delay(3000);
  }

  if ((recieveCount == 8) && (bufferSizeCount == 2))
  {
    long int f2 = recievedData[2] << 16;
    long int f1 = recievedData[3] << 8;
    long int f0 = recievedData[4] << 0;
    f = f2 + f1 + f0;
    flow = (float)f / 1000; //Akış değeri için HEX değeri 1000'e böl

    long int t1 = recievedData[5] << 8;
    long int t0 = recievedData[6] << 0;
    t = t1 + t0;
    temperature = (float)t / 10;

    Serial.print("Temp Hex: ");
    Serial.println(t);
    Serial.println("-------------------------------");
    Serial.print("Flow HEX: ");
    Serial.println(f);
    Serial.println("-------------------------------");
    Serial.println();
    Serial.println("-------------------------------");
    Serial.print("Temp: ");
    Serial.print(temperature);
    Serial.println(" °C");
    Serial.println("-------------------------------");
    Serial.print("Flow: ");
    Serial.print(flow);
    Serial.println(" lt/dk");
    Serial.println("-------------------------------");
    Serial.println();
    recieveCount = 0;
    bufferSizeCount = 0;
    delay(3000);
  }
  
  
}

Thank you in advance for your support.

If recieveCount is ever equal to 9, then you've overwritten the recievedData array whose indices run from 0 to 8.

could you upload a copy of the serial monitor as text (not an image) showing a program run followed by the crash

Temp: 24.20 °C

Flow: 0.63 lt/dk

Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x00000000 PS : 0x00060730 A0 : 0x800d0cf0 A1 : 0x3ffb1f50
A2 : 0x3ffbfe74 A3 : 0x3ffbfe66 A4 : 0x00000003 A5 : 0x3fe44189
A6 : 0x00000002 A7 : 0x00000000 A8 : 0x800d0fb3 A9 : 0x3ffb1f30
A10 : 0x3ffbfe74 A11 : 0x3ffbdf24 A12 : 0x3ffbfe69 A13 : 0x3fe9999c
A14 : 0x00000000 A15 : 0x00000003 SAR : 0x0000001e EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x4000c28c LEND : 0x4000c296 LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x00000000:0x3ffb1f50 0x400d0ced:0x3ffb1f70 0x400d0ee7:0x3ffb1f90 0x400d1835:0x3ffb1fb0 0x400860ed:0x3ffb1fd0

Rebooting...

$"⸮VdЌE⸮⸮D⸮D⸮⸮⸮!"j⸮ґ"NE"⸮Zj⸮Z⸮ґ"sZ⸮*}P)^⸮T⸮⸮)^⸮T⸮։YPC⸮(^⸮D։Ix⸮E"D⸮YR⸮
⸮F⸮-------------------------------
Temp: 24.20 °C

Flow: 0.39 lt/dk

Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x00000000 PS : 0x00060730 A0 : 0x800d0cf0 A1 : 0x3ffb1f50
A2 : 0x3ffbfe74 A3 : 0x3ffbfe66 A4 : 0x00000003 A5 : 0x3fd8e560
A6 : 0x00000002 A7 : 0x00000000 A8 : 0x800d0fb3 A9 : 0x3ffb1f30
A10 : 0x3ffbfe74 A11 : 0x3ffbdf24 A12 : 0x3ffbfe69 A13 : 0x3fd99998
A14 : 0x00000000 A15 : 0x00000009 SAR : 0x0000001b EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x4000c28c LEND : 0x4000c296 LCOUNT : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x00000000:0x3ffb1f50 0x400d0ced:0x3ffb1f70 0x400d0ee7:0x3ffb1f90 0x400d1835:0x3ffb1fb0 0x400860ed:0x3ffb1fd0

Rebooting...

I am sharing the serial monitor screen above. The data I want comes after the error. But I want to continue getting the data without any errors. This code works fine when I use Arduino MEGA instead of ESP32. I used Serial1 instead of Serial2 on Arduino.

You can check here: Guru Meditation Error: Core 1 panic’ed - ESP32 Forum

@gfvalvo makes a good point worth following up
also you never set up recievedData[0] - remember in C/C++ arrays start at index [0] and finish at index [SIZE-1]
while debugging your code could do with a few more print statements to show intermediate data and indicate the flow of the code