0

I am trying to serial print the value of b[0][0].

Has to be zero but it dose not work!

Here is the code

void setup() {
  Serial.begin(115200);
  byte b[321][241];
  Serial.println(b[0][0]);
}

void loop() {

}

If the array is small like b[2][2] it dose work

In theory esp32 has ram of ‎520 KiB SRAM so can this be a problem?

Here is the error code

rst:0x8 (TG1WDT_SYS_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:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8

The code complies fine but the error gets when esp32 is running

esp32 version for arduino is 1.0.4

  • what about b[2][241] or b[321][2] ? – jsotola Jun 8 at 8:00
  • Stack size is usually much smaller than RAM, especially if it's running under RTOS, so I'd expect problems with it. – KIIV Jun 8 at 8:05
  • @jsotola for b[321][2] I get the value 165 as output shouldn't it be zero also for b[2][241] is 165 – Avon Pubudu Jayaweera Jun 8 at 9:48
1

The ESP32 uses FreeRTOS to run everything, and that includes the Arduino API. Your code is running in a thread of its own ("loopTask"), and that task by default has 8192 bytes of stack allocated to it.

xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);

You cannot create local variables and other stack data that totals more than 8192 bytes.

Instead you will either have to have the variable as a global variable (or static local) so it gets allocated in the global data segment, or use new or malloc to create it on the heap (and don't forget the corresponding delete or free call when you're done with it).

| improve this answer | |
-1

This may be due to serial buffer size. ESP32 may wrire new data before finshing previous transfer. Add a delay after print line and see.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.