ESP32 error: "Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled."

I'm writing an Arduino program for an ESP32 dev board (this specific dev board: ESP32-DevKitC V4 Getting Started Guide - ESP32 - — ESP-IDF Programming Guide latest documentation). I'm writing a relatively simple program in which I'm trying to write to the I2C bus with GPIO pins 16 and 17 as SDA and SCL. In the main sketch file, I'm writing some arbitrary bytes to the I2C address 0x70. I don't actually have a device with that I2C address connected to the bus, but what I'm trying to do is simply verify that the ESP32 dev board is able to send a write request over the bus (of course, it won't get any response). What ends up happening, though, is apparently some sort of memory corruption error that somehow sets the Program Counter to 0x00000000.

My code:

#include <Arduino.h>
#include <Wire.h>

#define PIN_I2C_FAST_SDA 16
#define PIN_I2C_FAST_SCL 17

class CoreBoard {
  private:
    TwoWire *I2C_fast;
  public:
	  CoreBoard();
	  int I2CFastWrite(uint8_t address, uint8_t buf_out[], uint8_t len);
};

/* Constructor for the CoreBoard class. */
CoreBoard::CoreBoard() {
  TwoWire bus_fast = TwoWire(0);
  bus_fast.begin(PIN_I2C_FAST_SDA, PIN_I2C_FAST_SCL, 400000);
  I2C_fast = &(bus_fast);
	Serial.println("Initialized core board!");
}

/* Write to the I2C_FAST bus. */
int CoreBoard::I2CFastWrite(uint8_t address, uint8_t buf_out[], uint8_t len) {

  I2C_fast->beginTransmission(address);

  Serial.println("Contents of buf_out:");
  Serial.println(buf_out[0]);
  Serial.println(buf_out[1]);
  Serial.println(buf_out[2]);

  Serial.println("Preparing to do I2C Write");
  I2C_fast->write(buf_out, len);
  Serial.println("I2C Write sucessful");

  I2C_fast->endTransmission();
  return 0;

}

void setup() {
  Serial.begin(115200);
}

void loop() {
  CoreBoard core;
  uint8_t example_address = 0x70;
  uint8_t example_data[] = {0x41, 0x42, 0x43};
  while (true) {
    delay(1000);
    core.I2CFastWrite(example_address, example_data, 3);
  }
}

The printout that I get:

ELF file SHA256: 0000000000000000

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
Initialized core board!
Contents of buf_out:
65
66
67
Preparing to do I2C Write
Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x00000000  PS      : 0x00060a30  A0      : 0x800d1264  A1      : 0x3ffb27d0  
A2      : 0x3ffb27fc  A3      : 0x3ffc1280  A4      : 0x3ffb27f9  A5      : 0x00000003  
A6      : 0x00000001  A7      : 0x00000000  A8      : 0x800d11b3  A9      : 0x3ffb27b0  
A10     : 0x3ffb2784  A11     : 0x3ffb27f9  A12     : 0x00000003  A13     : 0x00061a80  
A14     : 0x3ffb7e50  A15     : 0x00000000  SAR     : 0x00000010  EXCCAUSE: 0x00000014  
EXCVADDR: 0x00000000  LBEG    : 0x400865b9  LEND    : 0x400865c9  LCOUNT  : 0xfffffffa  


Backtrace:0xfffffffd:0x3ffb27d00x400d1261:0x3ffb27f0 0x400d2845:0x3ffb2820 

From what I can tell, something must be going wrong in the line with "I2C_fast->write(buf_out, len);" because the pinout right before that line appears in the output, but the printout right after that line does not.
Earlier I was also getting a similar error, "Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled", but I'm having trouble reproducing that one.

would the following constructor work?

class CoreBoard {
  private:
    TwoWire *I2C_fast;
  public:
    CoreBoard();
    int I2CFastWrite(uint8_t address, uint8_t buf_out[], uint8_t len);
};

/* Constructor for the CoreBoard class. */
CoreBoard::CoreBoard() {
  I2C_fast = new TwoWire(0);
  I2C_fast->begin(PIN_I2C_FAST_SDA, PIN_I2C_FAST_SCL, 400000);
  Serial.println("Initialized core board!");
}
1 Like

This is a problem because 'I2C_fast' points to 'bus_fast' which is a local variable that goes out of scope.

1 Like

Thank you, this worked!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.