espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.67k stars 7.29k forks source link

ADC driver not initialized error (IDFGH-12728) #13711

Open simardeep272 opened 6 months ago

simardeep272 commented 6 months ago

Answers checklist.

General issue report

Hi,

I am trying to run a ADC based code to run my piezosensors. The code runs perfectly fine for a while and then displays error:

E (66155) adc_continuous: adc_continuous_read(436): The driver isn't initialised

I can't really pin what is causing this issue. My code is pretty much similar to the adc_continuous example. There are my defined macros:

MAX_BUFFER_SIZE 256 CONV_FRAME_SIZE 64

Furthermore, I am using xTaskCreate to call my read function: xTaskCreate(adc_read_continuous_mode, "adc_read_task", 5000, &handle, 1, NULL);

This is my output log: I (66085) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66085) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66095) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66105) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66115) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66125) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66125) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66135) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 I (66145) PiezoSensor: ADC Value: 0, Vibration Intensity: 0.00 E (66155) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66165) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66175) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66175) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66185) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66195) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66205) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66215) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66215) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66225) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66235) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66245) adc_continuous: adc_continuous_read(436): The driver isn't initialised E (66255) adc_continuous: adc_continuous_read(436): The driver isn't initialised

I'll appreciate any assistance regarding this issue. Thanks

suda-morris commented 6 months ago

The error log comes from ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_STATE, ADC_TAG, "The driver isn't initialised");

Are you passing a NULL as the handle to the adc_continuous_read by accident?

simardeep272 commented 6 months ago

Hi, thanks a lot for the reply.

I'm making sure that handle is not NULL, I am running the code below once to initialize my adc pins and then reading using xTaskCreate:

adc_continuous_handle_t initialize_adc_piezo(void)

{

adc_continuous_handle_t handle = NULL;

adc_continuous_handle_cfg_t adc_config = {
        .max_store_buf_size = MAX_BUFFER_SIZE,
    .conv_frame_size =  CONV_FRAME_SIZE
};

ESP_ERROR_CHECK(adc_continuous_new_handle(&adc_config, &handle));

adc_continuous_config_t adc_config_digi = {
    .sample_freq_hz = 6000,
    .conv_mode = ADC_CONV_SINGLE_UNIT_1,
    .format = ADC_DIGI_OUTPUT_FORMAT_TYPE2
};

adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};

adc_config_digi.pattern_num = 1;

adc_pattern[0].atten = ADC_ATTENUATION;
adc_pattern[0].channel = channel[0] & 0x7;
adc_pattern[0].unit = ADC_UNIT_1;
adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;

adc_config_digi.adc_pattern = adc_pattern;

ESP_ERROR_CHECK(adc_continuous_config(handle, &adc_config_digi));
ESP_ERROR_CHECK(adc_continuous_start(handle));

ESP_LOGI(TAG, "Sensor working");
return handle;
simardeep272 commented 6 months ago

Hi @suda-morris , can you please provide any assistance regarding this