Core 1 panic'ed InstrFetchProhibited measurement from i2s to array

rstjorden
Posts: 2
Joined: Sun Jan 12, 2020 7:37 pm

Core 1 panic'ed InstrFetchProhibited measurement from i2s to array

Postby rstjorden » Tue Jan 21, 2020 10:07 am

Hi,
I am trying to store samples from i2s mic to int32_t array,
The size of the array is 32000 to store 2 seconds of recording (16kHz, 32 bit every sample.)
I get this error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
When i reduce the array size to 200 it workes.

code:

Code: Select all


#include <driver/i2s.h> // I2S library

// var dec
const i2s_port_t I2S_PORT = I2S_NUM_0;                  
int i=0;
const int j=32000;
bool flag= false;
int32_t *sample_array;
void setup() {
sample_array = new int32_t(j);
  
  Serial.begin(115200);
  Serial.println("Configuring I2S...");
  esp_err_t err;

  //--------------------configuration of the I2S.-------------------//
  const i2s_config_t i2s_config = {
      .mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX), // Receive, not transfer
      .sample_rate = 16000,                              // 16KHz
      .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,      // 32bits per sample.
      .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,      // although the SEL config should be left, it seems to transmit on right
      .communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
      .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,          // Interrupt level 1
      .dma_buf_count = 4,                                // number of buffers
      .dma_buf_len = 8                                   // 8 samples per buffer (minimum)
  };

  //-------------------- The pin config as per the setup-------------------//
  const i2s_pin_config_t pin_config = {
      .bck_io_num = 14,   // BCKL
      .ws_io_num = 15,    // LRCL
      .data_out_num = -1, // not used (only for speakers)
      .data_in_num = 32   // DOUT
  };

  // Configuring the I2S driver and pins.
  // This function must be called before any I2S driver read/write operations.
  err = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
  if (err != ESP_OK) {
    Serial.printf("Failed installing driver: %d\n", err);
    while (true);
  }
  err = i2s_set_pin(I2S_PORT, &pin_config);
  if (err != ESP_OK) {
    Serial.printf("Failed setting pin: %d\n", err);
    while (true);
  }
  Serial.println("I2S driver installed.");
}

void loop() {
  int32_t sample = 0;
  int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout
  if(abs(sample)>25000000)
  {
      digitalWrite(ledPin,HIGH);
      flag=true;
  }
  if(flag)
  {
    delay(0.0000625);
    sample_array[i]=sample;
    i++;
    if(i==(j))
    {
      digitalWrite(ledPin,LOW);
      flag=false;
      Serial.println("ending");
      for(int k = 0; k < j; k++)
      {
      Serial.println(sample_array[k]);
      }
      i=0;
      free(sample_array);
    }
  }
}
Thank you.

Who is online

Users browsing this forum: Bing [Bot] and 123 guests