'I2S_MODE_ADC_BUILT_IN' was not declared in this scope for ESP32S3?

lladam
Posts: 44
Joined: Tue Jul 20, 2021 12:14 am

'I2S_MODE_ADC_BUILT_IN' was not declared in this scope for ESP32S3?

Postby lladam » Wed Apr 26, 2023 3:36 pm

Hi all.
the ESP32 example got compiling error for ESP32S3, passed compiling for ESP32 , why?

CODE:

Code: Select all

#include <driver/i2s.h>

// I2S
#define I2S_SAMPLE_RATE (277777) // Max sampling frequency = 277.777 kHz
#define ADC_INPUT (ADC1_CHANNEL_4) //pin 32
#define I2S_DMA_BUF_LEN (1024)

// PWM
#define GENERATE_PWM
#define OUTPUT_PIN (27)
#define PWM_FREQUENCY ((I2S_SAMPLE_RATE)/4)
#define PWM_DUTY_PERCENT (50)
#define PWM_RESOLUTION_BITS (2) // Lower bit resolution enables higher frequency
#define PWM_DUTY_VALUE ((((1<<(PWM_RESOLUTION_BITS)))*(PWM_DUTY_PERCENT))/100) // Duty value used for setup function based on resolution

// Sample post processing
#define PRINT_ALL_VALUES
#define AVERAGE_EVERY_N_SAMPLES (100)

void i2sInit(){
  i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),
    .sample_rate =  I2S_SAMPLE_RATE,              // The format of the signal using ADC_BUILT_IN
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB
    .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
    .communication_format = I2S_COMM_FORMAT_STAND_I2S,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count = 8,
    .dma_buf_len = I2S_DMA_BUF_LEN,
    .use_apll = false,
    .tx_desc_auto_clear = false,
    .fixed_mclk = 0
  };
  Serial.printf("Attempting to setup I2S ADC with sampling frequency %d Hz\n", I2S_SAMPLE_RATE);
  if(ESP_OK != i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL)){
    Serial.printf("Error installing I2S. Halt!");
    while(1);
  }
  if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){
    Serial.printf("Error setting up ADC. Halt!");
    while(1);
  }
  if(ESP_OK != adc1_config_channel_atten(ADC_INPUT, ADC_ATTEN_DB_11)){
    Serial.printf("Error setting up ADC attenuation. Halt!");
    while(1);
  }

  if(ESP_OK != i2s_adc_enable(I2S_NUM_0)){
    Serial.printf("Error enabling ADC. Halt!");
    while(1);
  }
  Serial.printf("I2S ADC setup ok\n");
}

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

#ifdef GENERATE_PWM
  // PWM setup
  Serial.printf("Setting up PWM: frequency = %d; resolution bits %d; Duty cycle = %d; duty value = %d, Output pin = %d\n", PWM_FREQUENCY, PWM_RESOLUTION_BITS, PWM_DUTY_PERCENT, PWM_DUTY_VALUE, OUTPUT_PIN);
  uint32_t freq = ledcSetup(0, PWM_FREQUENCY, PWM_RESOLUTION_BITS);
  if(freq != PWM_FREQUENCY){
    Serial.printf("Error setting up PWM. Halt!");
    while(1);
  }
  ledcAttachPin(OUTPUT_PIN, 0);
  ledcWrite(0, PWM_DUTY_VALUE);
  Serial.printf("PWM setup ok\n");
#endif

  // Initialize the I2S peripheral
  i2sInit();
}

void loop(){
// The 4 high bits are the channel, and the data is inverted
  size_t bytes_read;
  uint16_t buffer[I2S_DMA_BUF_LEN] = {0};

#ifdef AVERAGE_EVERY_N_SAMPLES
  uint32_t read_counter = 0;
  uint32_t averaged_reading = 0;
  uint64_t read_sum = 0;
#endif

  while(1){
    i2s_read(I2S_NUM_0, &buffer, sizeof(buffer), &bytes_read, 15);
    //Serial.printf("read %d Bytes\n", bytes_read);

    for(int i = 0; i < bytes_read/2; ++i){
#ifdef PRINT_ALL_VALUES
      //Serial.printf("[%d] = %d\n", i, buffer[i] & 0x0FFF); // Print with indexes
      Serial.printf("Signal:%d ", buffer[i] & 0x0FFF); // Print compatible with Arduino Plotter
#endif
#ifdef AVERAGE_EVERY_N_SAMPLES
      read_sum += buffer[i] & 0x0FFF;
      ++read_counter;
      if(read_counter == AVERAGE_EVERY_N_SAMPLES){
        averaged_reading = read_sum / AVERAGE_EVERY_N_SAMPLES;
        //Serial.printf("averaged_reading = %d over %d samples\n", averaged_reading, read_counter); // Print with additional info
        Serial.printf("Averaged_signal:%d", averaged_reading); // Print compatible with Arduino Plotter
        read_counter = 0;
        read_sum = 0;
      }
#endif
#if defined(PRINT_ALL_VALUES) || defined (AVERAGE_EVERY_N_SAMPLES)
      Serial.printf("\n");
#endif
    } // for
  } // while
}
ERROR:

Code: Select all

Arduino: 1.8.19 (Windows 10), Board: "ESP32S3 Dev Module, Disabled, Disabled, QIO 80MHz, 4MB (32Mb), Core 1, Core 1, Hardware CDC and JTAG, Disabled, Disabled, Disabled, UART0 / Hardware CDC, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi), 921600, None, Disabled"

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino: In function 'void i2sInit()':

HiFreq_ADC:44:58: error: 'I2S_MODE_ADC_BUILT_IN' was not declared in this scope

     .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),

                                                          ^~~~~~~~~~~~~~~~~~~~~

HiFreq_ADC:61:33: error: 'ADC_UNIT_1' was not declared in this scope

   if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){

                                 ^~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:61:33: note: suggested alternative: 'ADC_INPUT'

   if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){

                                 ^~~~~~~~~~

                                 ADC_INPUT

HiFreq_ADC:27:20: error: 'ADC1_CHANNEL_4' was not declared in this scope

 #define ADC_INPUT (ADC1_CHANNEL_4) //pin 32

                    ^~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:61:45: note: in expansion of macro 'ADC_INPUT'

   if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){

                                             ^~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:27:20: note: suggested alternative: 'I2S_CHANNEL_MONO'

 #define ADC_INPUT (ADC1_CHANNEL_4) //pin 32

                    ^~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:61:45: note: in expansion of macro 'ADC_INPUT'

   if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){

                                             ^~~~~~~~~

HiFreq_ADC:61:16: error: 'i2s_set_adc_mode' was not declared in this scope

   if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){

                ^~~~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:61:16: note: suggested alternative: 'i2s_set_clk'

   if(ESP_OK != i2s_set_adc_mode(ADC_UNIT_1, ADC_INPUT)){

                ^~~~~~~~~~~~~~~~

                i2s_set_clk

HiFreq_ADC:27:20: error: 'ADC1_CHANNEL_4' was not declared in this scope

 #define ADC_INPUT (ADC1_CHANNEL_4) //pin 32

                    ^~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:65:42: note: in expansion of macro 'ADC_INPUT'

   if(ESP_OK != adc1_config_channel_atten(ADC_INPUT, ADC_ATTEN_DB_11)){

                                          ^~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:27:20: note: suggested alternative: 'I2S_CHANNEL_MONO'

 #define ADC_INPUT (ADC1_CHANNEL_4) //pin 32

                    ^~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:65:42: note: in expansion of macro 'ADC_INPUT'

   if(ESP_OK != adc1_config_channel_atten(ADC_INPUT, ADC_ATTEN_DB_11)){

                                          ^~~~~~~~~

HiFreq_ADC:65:53: error: 'ADC_ATTEN_DB_11' was not declared in this scope

   if(ESP_OK != adc1_config_channel_atten(ADC_INPUT, ADC_ATTEN_DB_11)){

                                                     ^~~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:65:53: note: suggested alternative: 'ADC_ATTENDB_MAX'

   if(ESP_OK != adc1_config_channel_atten(ADC_INPUT, ADC_ATTEN_DB_11)){

                                                     ^~~~~~~~~~~~~~~

                                                     ADC_ATTENDB_MAX

HiFreq_ADC:65:16: error: 'adc1_config_channel_atten' was not declared in this scope

   if(ESP_OK != adc1_config_channel_atten(ADC_INPUT, ADC_ATTEN_DB_11)){

                ^~~~~~~~~~~~~~~~~~~~~~~~~

HiFreq_ADC:70:16: error: 'i2s_adc_enable' was not declared in this scope

   if(ESP_OK != i2s_adc_enable(I2S_NUM_0)){

                ^~~~~~~~~~~~~~

C:\Users\Xinzhou\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.8\libraries\ESP32\examples\I2S\HiFreq_ADC\HiFreq_ADC.ino:70:16: note: suggested alternative: 'esp_intr_enable'

   if(ESP_OK != i2s_adc_enable(I2S_NUM_0)){

                ^~~~~~~~~~~~~~

                esp_intr_enable

exit status 1

'I2S_MODE_ADC_BUILT_IN' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

ESP_Sprite
Posts: 9577
Joined: Thu Nov 26, 2015 4:08 am

Re: 'I2S_MODE_ADC_BUILT_IN' was not declared in this scope for ESP32S3?

Postby ESP_Sprite » Thu Apr 27, 2023 1:23 am

The S3 has the ADC as its own peripheral that is DMA-capable rather than using the I2S peripheral for that. See the adc_digi_* function calls here for how to use that.

natee.th
Posts: 26
Joined: Fri Feb 10, 2023 5:25 pm

Re: 'I2S_MODE_ADC_BUILT_IN' was not declared in this scope for ESP32S3?

Postby natee.th » Mon May 06, 2024 3:04 am

Hello ESP_Sprite
In the adc_continuous folder is a shortened example. that is not much for understanding. I need to get ADC DMA used for audio FFT. Can you suggest that? I need to get 12-bit 48000Hz and buffer length 16.

Who is online

Users browsing this forum: Basalt, Google [Bot] and 228 guests