Good afternoon, I hope you are well.
I'm new here on SO, I apologize in advance for my English.
I'm doing a project with 4 accelerometers and a TCA9548A multiplexer to talk to an esp32. The samples of the 4 sensors are correct, but this error appears "ESP32: Guru Meditation Error: Core 1 panic'ed (StoreProhibited)" at the beginning of each sample, and I would like to know what I could modify in the code to resolve this error.
#include <Adafruit_MPU6050.h> #include <Adafruit_Sensor.h> #include <Wire.h> Adafruit_MPU6050 mpu1; Adafruit_MPU6050 mpu2; Adafruit_MPU6050 mpu3; Adafruit_MPU6050 mpu4; unsigned long _time; void TCA9548A(uint8_t bus){ Wire.beginTransmission(0x70); // TCA9548A address Wire.write(1 << bus); // send byte to select bus Wire.endTransmission(); } void printValues(Adafruit_MPU6050 mpu, int bus) { sensors_event_t a, g, temp; mpu.getEvent(&a, &g, &temp); TCA9548A (bus); Serial.print("Sensor: "); Serial.println(bus); Serial.print("Eixo X:"); Serial.print(a.acceleration.x); Serial.print(" m/s^2, "); Serial.print("\tEixo Y:"); Serial.print(a.acceleration.y); Serial.print(" m/s^2, "); Serial.print("\tEixo Z:"); Serial.print(a.acceleration.z); Serial.print(" m/s^2,"); Serial.print("\t Temperatura: "); Serial.print(temp.temperature); Serial.println(" °C"); } void setup(void) { Serial.begin(115200); Wire.begin(); TCA9548A(2); if (!mpu1.begin(0x68)) { Serial.println("Could not find a valid BME280 sensor on bus 2, check wiring!"); while (1); } Serial.println(); // Init sensor on bus number 3 TCA9548A(3); if (!mpu2.begin(0x68)) { Serial.println("Could not find a valid BME280 sensor on bus 3, check wiring!"); while (1); } Serial.println(); // Init sensor on bus number 4 TCA9548A(4); if (!mpu3.begin(0x68)) { Serial.println("Could not find a valid BME280 sensor on bus 4, check wiring!"); while (1); } Serial.println(); // Init sensor on bus number 5 TCA9548A(5); if (!mpu4.begin(0x68)) { Serial.println("Could not find a valid BME280 sensor on bus 5, check wiring!"); while (1); } Serial.println(); } void loop() { printValues(mpu1, 2); printValues(mpu2, 3); printValues(mpu3, 4); printValues(mpu4, 5); yield(); delay(100); }
On the serial monitor I get the following result
Sensor: 2 Eixo X:-0.72 m/s^2, Eixo Y:-0.03 m/s^2, Eixo Z:9.71 m/s^2, Temperatura: 26.84 °C Sensor: 3 Eixo X:0.36 m/s^2, Eixo Y:-0.27 m/s^2, Eixo Z:8.31 m/s^2, Temperatura: 24.62 °C Sensor: 4 Eixo X:0.16 m/s^2, Eixo Y:-0.19 m/s^2, Eixo Z:9.86 m/s^2, Temperatura: 27.26 °C Sensor: 5 Eixo X:0.71 m/s^2, Eixo Y:0.10 m/s^2, Eixo Z:9.82 m/s^2, Temperatura: 27.02 °C Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled. Core 1 register dump: PC : 0x400ebac0 PS : 0x00060130 A0 : 0x800d19a2 A1 : 0x3ffb1db0 A2 : 0x00010001 A3 : 0x000000ae A4 : 0x00060023 A5 : 0x3ffb8058 A6 : 0x00000000 A7 : 0x00000000 A8 : 0x00010101 A9 : 0x00000001 A10 : 0x3ffc02ac A11 : 0x3ffc0110 A12 : 0x00000020 A13 : 0x80000020 A14 : 0x00000008 A15 : 0x00000001 SAR : 0x0000000a EXCCAUSE: 0x0000001d EXCVADDR: 0x00010127 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff ELF file SHA256: 0000000000000000 Backtrace: 0x400ebac0:0x3ffb1db0 0x400d199f:0x3ffb1dd0 0x400d1a6a:0x3ffb1df0 0x400d1819:0x3ffb1e10 0x400d1492:0x3ffb1e40 0x400d16e2:0x3ffb1e90 0x400d0e99:0x3ffb1eb0 0x400d0f5e:0x3ffb1f40 0x400d3999:0x3ffb1fb0 0x400869bd:0x3ffb1fd0 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:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8
I went to the board manager and updated esp32, then when compiling the algorithm the following error appeared:
CORRUPT HEAP: Bad head at 0x3ffb94ec. Expected 0xabba1234 got 0x3ffb8014 assert failed: multi_heap_free multi_heap_poisoning.c:253 (head != NULL) Backtrace:0x400837b9:0x3ffb25800x40088135:0x3ffb25a0 0x4008d001:0x3ffb25c0 0x4008cc67:0x3ffb26f0 0x40083ae9:0x3ffb2710 0x4008d031:0x3ffb2730 0x400e1d41:0x3ffb2750 0x400d1591:0x3ffb2770 0x400d1697:0x3ffb2790 0x400d143e:0x3ffb27b0 0x400d3e19:0x3ffb2820 ELF file SHA256: 0000000000000000 Rebooting... ets Jun 8 2016 00:22:57 rst:0xc (SW_CPU_RESET),boot:0x17 (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:1184 load:0x40078000,len:13160 load:0x40080400,len:3036 entry 0x400805e4
when running the tool, I got the following result:
Decoding stack results 0x400837b9: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c line 402 0x40088135: esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c line 128 0x4008d001: __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c line 85 0x4008cc67: multi_heap_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/multi_heap_poisoning.c line 245 0x40083ae9: heap_caps_free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/heap/heap_caps.c line 340 0x4008d031: free at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/heap.c line 39 0x400e1d41: operator delete(void*) at /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/del_op.cc line 49 0x400d1591: Adafruit_MPU6050_Temp::~Adafruit_MPU6050_Temp() at C:\Users\thiag\Documents\Arduino\libraries\Adafruit_Sensor-master/Adafruit_Sensor.h line 165 0x400d1697: Adafruit_MPU6050::~Adafruit_MPU6050() at C:\Users\thiag\Documents\Arduino\libraries\Adafruit_MPU6050\Adafruit_MPU6050.cpp line 50 0x400d143e: loop() at C:\Users\thiag\Desktop\Trabalho/Trabalho.ino line 74 0x400d3e19: loopTask(void*) at C:\Users\thiag\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\cores\esp32\main.cpp line 50
41 Answer
void printValues(Adafruit_MPU6050 mpu, int bus)
When you passing in an argument to a function, the function create a copy of whatever you are passing in as the parameter, in your code, you are passing an entire instance of Adafruit_MPU6050
object, which is big. What you should do is to change your code to pass in the pointer to the object (which is only 16-bit in Arduino) to the function.
void printValues(Adafruit_MPU6050* mpu, int bus) { // passing pointer of mpu object TCA9548A (bus); sensors_event_t a, g, temp; mpu->getEvent(&a, &g, &temp); // using pointer notation // rest of your code }
I don't have the same hardware configuration as yours to test this code, you need to try and test it to confirm if this is working.
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobm1sYGmFcoKOnqqpa2JitLa%2B1GaknpyZqa61tc6nZJ6qoqS%2Fbq%2FOq5xmaV2lrq%2B1wp6bZqukpL%2BmvNGon6KamamypXnIp2SgsWVnfm61kZxkqaqf